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>
.
fn encoding_length(&self) -> Result<usize>
fn encoding_length(&self) -> Result<usize>
Calculates the length of the encoding for this value. Can error for types where invalid values are possible.
Provided methods
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
.
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.
impl<A: Encode + Terminated, B: Encode + Terminated, C: Encode + Terminated, D: Encode> Encode for (A, B, C, D)
impl<A: Encode + Terminated, B: Encode + Terminated, C: Encode + Terminated, D: Encode> Encode for (A, B, C, D)
Encodes the fields of the tuple one after another, in order.
Returns the sum of the encoding lengths of the fields of the tuple.
impl<A: Encode + Terminated, B: Encode + Terminated, C: Encode + Terminated, D: Encode + Terminated, E: Encode> Encode for (A, B, C, D, E)
impl<A: Encode + Terminated, B: Encode + Terminated, C: Encode + Terminated, D: Encode + Terminated, E: Encode> Encode for (A, B, C, D, E)
Encodes the fields of the tuple one after another, in order.
Returns the sum of the encoding lengths of the fields of the tuple.
impl<A: Encode + Terminated, B: Encode + Terminated, C: Encode + Terminated, D: Encode + Terminated, E: Encode + Terminated, F: Encode> Encode for (A, B, C, D, E, F)
impl<A: Encode + Terminated, B: Encode + Terminated, C: Encode + Terminated, D: Encode + Terminated, E: Encode + Terminated, F: Encode> Encode for (A, B, C, D, E, F)
Encodes the fields of the tuple one after another, in order.
Returns the sum of the encoding lengths of the fields of the tuple.
impl<A: Encode + Terminated, B: Encode + Terminated, C: Encode + Terminated, D: Encode + Terminated, E: Encode + Terminated, F: Encode + Terminated, G: Encode> Encode for (A, B, C, D, E, F, G)
impl<A: Encode + Terminated, B: Encode + Terminated, C: Encode + Terminated, D: Encode + Terminated, E: Encode + Terminated, F: Encode + Terminated, G: Encode> Encode for (A, B, C, D, E, F, G)
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.
Returns the encoding length of the inner value.