pub trait Encode<'a>{
// Provided methods
fn decode(s: &'a [u8]) -> Result<Self, Error> { ... }
fn encode_vec(&self) -> Result<Vec<u8>, Error> { ... }
fn encode_buf<'b>(&self, buf: &'b mut [u8]) -> Result<&'b mut [u8], Error> { ... }
fn size(&self) -> usize { ... }
}
Provided Methods§
Sourcefn decode(s: &'a [u8]) -> Result<Self, Error>
fn decode(s: &'a [u8]) -> Result<Self, Error>
Load object from bytes generated by [Encode::encode
].
§Errors
May return an error if the buffer does not contain a valid object.
Sourcefn encode_vec(&self) -> Result<Vec<u8>, Error>
fn encode_vec(&self) -> Result<Vec<u8>, Error>
Encode the object as a Vec.
If you want to avoid dynamic allocations, use Encode::encode_buf
instead.
§Errors
In theory, may return an error if any of the types cannot be serialized by postcard. However, all the types defined in this crate are very simple, so it shouldn’t happen.
Sourcefn encode_buf<'b>(&self, buf: &'b mut [u8]) -> Result<&'b mut [u8], Error>
fn encode_buf<'b>(&self, buf: &'b mut [u8]) -> Result<&'b mut [u8], Error>
Encode the object using the buffer.
The buffer is required to avoid allocations on the crate side.
Use Encode::size
to calculate the required buffer size.
§Errors
May return an error if the buffer is not big enough.
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.