Trait Encode Copy item path Source pub trait Encode {
// Required methods
fn encode_into <W: Write >(&self, dest: &mut W ) -> Result <() >;
fn encoding_length (&self) -> Result <usize >;
// Provided method
fn encode (&self) -> Result <Vec <u8 >> { ... }
}Expand description A trait for values that can be encoded into bytes deterministically.
Writes the encoded representation of the value to the destination
writer. Can error due to either a write error from dest, or an
encoding error for types where invalid values are possible.
It may be more convenient to call encode which
returns bytes, however encode_into will often be more efficient since
it can write the encoding without necessarily allocating a new
Vec<u8>.
Calculates the length of the encoding for this value. Can error for
types where invalid values are possible.
Returns the encoded representation of the value as a Vec<u8>.
While this method is convenient, it will often be more efficient to call
encode_into since encode usually involves
allocating a new Vec<u8>.
This trait is not dyn compatible .
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Encodes the boolean as a single byte: 0 for false or 1 for true.
Encodes the integer as fixed-size big-endian bytes.
Returns the size of the integer in bytes. Will always
return an Ok result.
Encodes the integer as fixed-size big-endian bytes.
Returns the size of the integer in bytes. Will always
return an Ok result.
Encodes the integer as fixed-size big-endian bytes.
Returns the size of the integer in bytes. Will always
return an Ok result.
Encodes the integer as fixed-size big-endian bytes.
Returns the size of the integer in bytes. Will always
return an Ok result.
Encodes the integer as fixed-size big-endian bytes.
Returns the size of the integer in bytes. Will always
return an Ok result.
Encodes the integer as fixed-size big-endian bytes.
Returns the size of the integer in bytes. Will always
return an Ok result.
Encodes the integer as fixed-size big-endian bytes.
Returns the size of the integer in bytes. Will always
return an Ok result.
Encodes the integer as fixed-size big-endian bytes.
Returns the size of the integer in bytes. Will always
return an Ok result.
Encodes the integer as fixed-size big-endian bytes.
Returns the size of the integer in bytes. Will always
return an Ok result.
Encodes the integer as fixed-size big-endian bytes.
Returns the size of the integer in bytes. Will always
return an Ok result.
Encoding a unit tuple is a no-op.
Encodes the fields of the tuple one after another, in
order.
Returns the sum of the encoding lengths of the fields of
the tuple.
Encodes the fields of the tuple one after another, in
order.
Returns the sum of the encoding lengths of the fields of
the tuple.
Encodes the fields of the tuple one after another, in
order.
Returns the sum of the encoding lengths of the fields of
the tuple.
Encodes the fields of the tuple one after another, in
order.
Returns the sum of the encoding lengths of the fields of
the tuple.
Encodes the fields of the tuple one after another, in
order.
Returns the sum of the encoding lengths of the fields of
the tuple.
Encodes the fields of the tuple one after another, in
order.
Returns the sum of the encoding lengths of the fields of
the tuple.
Encodes the fields of the tuple one after another, in
order.
Returns the sum of the encoding lengths of the fields of
the tuple.
Encodes the fields of the tuple one after another, in
order.
Returns the sum of the encoding lengths of the fields of
the tuple.
Encodes the fields of the tuple one after another, in
order.
Returns the sum of the encoding lengths of the fields of
the tuple.
Encodes the fields of the tuple one after another, in
order.
Returns the sum of the encoding lengths of the fields of
the tuple.
Encodes the fields of the tuple one after another, in
order.
Returns the sum of the encoding lengths of the fields of
the tuple.
Encodes the fields of the tuple one after another, in
order.
Returns the sum of the encoding lengths of the fields of
the tuple.
Encoding PhantomData is a no-op.
Encodes the elements of the slice one after another, in order.
Returns the sum of the encoding lengths of all elements.
Encodes the elements of the vector one after another, in order.
Returns the sum of the encoding lengths of all elements.
Encodes as a 0 byte for None, or as a 1 byte followed by the encoding of
the inner value for Some.
Length will be 1 for None, or 1 plus the encoding length of the inner
value for Some.
Returns the encoding length of the inner value.