refactor: rename encode_decode with codec

This commit is contained in:
Vincent Herlemont
2023-10-29 09:40:24 +01:00
parent 789f09fa67
commit ac601f4c98
2 changed files with 2 additions and 2 deletions
+34
View File
@@ -0,0 +1,34 @@
/// Encode trait for your own encoding method.
///
/// Example:
/// ```rust
/// pub struct Bincode;
///
/// impl<T: bincode::Encode> native_model::Encode<T> for Bincode {
/// type Error = bincode::error::EncodeError;
/// fn encode(obj: &T) -> Result<Vec<u8>, bincode::error::EncodeError> {
/// bincode::encode_to_vec(obj, bincode::config::standard())
/// }
/// }
/// ```
pub trait Encode<T> {
type Error;
fn encode(obj: &T) -> Result<Vec<u8>, Self::Error>;
}
/// Decode trait for your own decoding method.
///
/// Example:
/// ```rust
/// pub struct Bincode;
///
/// impl<T: bincode::Decode> native_model::Decode<T> for Bincode {
/// type Error = bincode::error::DecodeError;
/// fn decode(data: Vec<u8>) -> Result<T, bincode::error::DecodeError> {
/// bincode::decode_from_slice(&data, bincode::config::standard()).map(|(result, _)| result)
/// }
/// }
pub trait Decode<T> {
type Error;
fn decode(data: Vec<u8>) -> Result<T, Self::Error>;
}