pub trait Encode {
// Provided methods
fn size_hint(&self) -> usize { ... }
fn encode_to<T: Output + ?Sized>(&self, dest: &mut T) { ... }
fn encode(&self) -> Vec<u8> ⓘ { ... }
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R { ... }
fn encoded_size(&self) -> usize { ... }
}
Expand description
Trait that allows zero-copy write of value-references to slices in LE format.
Implementations should override using_encoded
for value types and encode_to
and size_hint
for allocating types. Wrapper types should override all methods.
Provided Methods§
Sourcefn size_hint(&self) -> usize
fn size_hint(&self) -> usize
If possible give a hint of expected size of the encoding.
This method is used inside default implementation of encode
to avoid re-allocations.
Sourcefn encode_to<T: Output + ?Sized>(&self, dest: &mut T)
fn encode_to<T: Output + ?Sized>(&self, dest: &mut T)
Convert self to a slice and append it to the destination.
Sourcefn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R
Convert self to a slice and then invoke the given closure with it.
Sourcefn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
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.