pub trait Encode {
    fn size_hint(&self) -> usize { ... }
fn encode_to<T: Output + ?Sized>(&self, dest: &mut T) { ... }
fn encode(&self) -> Vec<u8>Notable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
    A: Allocator
{ ... }
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

If possible give a hint of expected size of the encoding.

This method is used inside default implementation of encode to avoid re-allocations.

Convert self to a slice and append it to the destination.

Convert self to an owned vector.

Convert self to a slice and then invoke the given closure with it.

Calculates the encoded size.

Should be used when the encoded data isn’t required.

Note

This works by using a special Output that only tracks the size. So, there are no allocations inside the output. However, this can not prevent allocations that some types are doing inside their own encoding.

Implementations on Foreign Types

Implementors