Skip to main content

Serializable

Trait Serializable 

Source
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§

Source

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
Source

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".

Implementors§

Source§

impl<R: Request, K: SignatureKey> Serializable for Message<R, K>

A blanket implementation of the Serializable trait for any Message

Source§

impl<R: Request, K: SignatureKey> Serializable for RequestMessage<R, K>

Source§

impl<R: Request> Serializable for ResponseMessage<R>