pub trait Variable: Sized {
// Required methods
fn encode_variable<W: Write>(&self, destination: W) -> Result<usize>;
fn decode_variable<R: Read>(source: R) -> Result<Self>;
// Provided method
fn to_variable_vec(&self) -> Result<Vec<u8>> { ... }
}
Expand description
Encodes and decodes a type using a variable-length format.
Required Methods§
Sourcefn encode_variable<W: Write>(&self, destination: W) -> Result<usize>
fn encode_variable<W: Write>(&self, destination: W) -> Result<usize>
Encodes self
into destination
, returning the number of bytes written upon success.
Sourcefn decode_variable<R: Read>(source: R) -> Result<Self>
fn decode_variable<R: Read>(source: R) -> Result<Self>
Decodes a variable length value from source
.
Provided Methods§
Sourcefn to_variable_vec(&self) -> Result<Vec<u8>>
fn to_variable_vec(&self) -> Result<Vec<u8>>
Encodes self
into a new Vec<u8>
.
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.