refactor: rename encode_decode with codec
This commit is contained in:
@@ -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>;
|
||||
}
|
||||
Reference in New Issue
Block a user