Trait ed::Encode[][src]

pub trait Encode {
    fn encode_into<W: Write>(&self, dest: &mut W) -> Result<()>;
fn encoding_length(&self) -> Result<usize>; fn encode(&self) -> Result<Vec<u8>> { ... } }
Expand description

A trait for values that can be encoded into bytes deterministically.

Required methods

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.

Provided methods

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>.

Implementations on Foreign Types

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.

Encodes the boolean as a single byte: 0 for false or 1 for true.

Always returns Ok(1).

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.

Encoding a unit tuple is a no-op.

Always returns Ok(0).

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 elements of the vector one after another, in order.

Returns the sum of the encoding lengths of all elements.

Encodes the elements of the slice one after another, in order.

Returns the sum of the encoding lengths of all elements.

Encodes the inner value.

Returns the encoding length of the inner value.

Implementors