pub trait Serializable: Sized {
// Required methods
fn to_bytes(&self) -> Result<Vec<u8>>;
fn from_bytes(bytes: &[u8]) -> Result<Self>;
}
Expand description
A trait for serializing and deserializing a type to and from a byte array. Request
types and
[Response
] types will need to implement this trait
Required Methods§
Sourcefn to_bytes(&self) -> Result<Vec<u8>>
fn to_bytes(&self) -> Result<Vec<u8>>
Serialize the type to a byte array. If this is for a Request
and your Request
type
is represented as an enum, please make sure that you serialize it with a unique type ID. Otherwise,
you may end up with collisions as the request hash is used as a unique identifier
§Errors
- If the type cannot be serialized to a byte array
Sourcefn from_bytes(bytes: &[u8]) -> Result<Self>
fn from_bytes(bytes: &[u8]) -> Result<Self>
Deserialize the type from a byte array
§Errors
- If the byte array is not a valid representation of the type
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl<R: Request> Serializable for ResponseMessage<R>
impl<R: Request, K: SignatureKey> Serializable for Message<R, K>
A blanket implementation of the Serializable
trait for any Message