Decode

Trait Decode 

Source
pub trait Decode: Sized {
    // Required method
    fn decode<R: Read>(input: R) -> Result<Self>;

    // Provided method
    fn decode_into<R: Read>(&mut self, input: R) -> Result<()> { ... }
}
Expand description

A trait for values that can be decoded from bytes deterministically.

Required Methods§

Source

fn decode<R: Read>(input: R) -> Result<Self>

Reads bytes from the reader and returns the decoded value.

When possible, calling decode_into will often be more efficient since it lets the caller reuse memory to avoid allocating for fields with types such as Vec<T>.

Provided Methods§

Source

fn decode_into<R: Read>(&mut self, input: R) -> Result<()>

Reads bytes from the reader and mutates self to the decoded value.

This is often more efficient than calling decode when reading fields with heap-allocated types such as Vec<T> since it can reuse the memory already allocated in self.

When possible, implementations should recursively call decode_into on any child fields.

The default implementation of decode_into simply calls decode for ease of implementation, but should be overridden when in-place decoding is possible.

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.

Implementations on Foreign Types§

Source§

impl Decode for bool

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Decodes the boolean from a single byte: 0 for false or 1 for true. Errors for any other value.

Source§

impl Decode for i8

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Decodes the integer from fixed-size big-endian bytes.

Source§

impl Decode for i16

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Decodes the integer from fixed-size big-endian bytes.

Source§

impl Decode for i32

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Decodes the integer from fixed-size big-endian bytes.

Source§

impl Decode for i64

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Decodes the integer from fixed-size big-endian bytes.

Source§

impl Decode for i128

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Decodes the integer from fixed-size big-endian bytes.

Source§

impl Decode for u8

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Decodes the integer from fixed-size big-endian bytes.

Source§

impl Decode for u16

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Decodes the integer from fixed-size big-endian bytes.

Source§

impl Decode for u32

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Decodes the integer from fixed-size big-endian bytes.

Source§

impl Decode for u64

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Decodes the integer from fixed-size big-endian bytes.

Source§

impl Decode for u128

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Decodes the integer from fixed-size big-endian bytes.

Source§

impl Decode for ()

Source§

fn decode<R: Read>(_: R) -> Result<Self>

Returns a unit tuple without reading any bytes.

Source§

impl<A: Decode + Terminated, B: Decode + Terminated, C: Decode + Terminated, D: Decode + Terminated, E: Decode + Terminated, F: Decode + Terminated, G: Decode + Terminated, H: Decode + Terminated, I: Decode + Terminated, J: Decode + Terminated, K: Decode + Terminated, L: Decode> Decode for (A, B, C, D, E, F, G, H, I, J, K, L)

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Decodes the fields of the tuple one after another, in order.

Source§

fn decode_into<R: Read>(&mut self, input: R) -> Result<()>

Decodes the fields of the tuple one after another, in order.

Recursively calls decode_into for each field.

Source§

impl<A: Decode + Terminated, B: Decode + Terminated, C: Decode + Terminated, D: Decode + Terminated, E: Decode + Terminated, F: Decode + Terminated, G: Decode + Terminated, H: Decode + Terminated, I: Decode + Terminated, J: Decode + Terminated, K: Decode> Decode for (A, B, C, D, E, F, G, H, I, J, K)

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Decodes the fields of the tuple one after another, in order.

Source§

fn decode_into<R: Read>(&mut self, input: R) -> Result<()>

Decodes the fields of the tuple one after another, in order.

Recursively calls decode_into for each field.

Source§

impl<A: Decode + Terminated, B: Decode + Terminated, C: Decode + Terminated, D: Decode + Terminated, E: Decode + Terminated, F: Decode + Terminated, G: Decode + Terminated, H: Decode + Terminated, I: Decode + Terminated, J: Decode> Decode for (A, B, C, D, E, F, G, H, I, J)

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Decodes the fields of the tuple one after another, in order.

Source§

fn decode_into<R: Read>(&mut self, input: R) -> Result<()>

Decodes the fields of the tuple one after another, in order.

Recursively calls decode_into for each field.

Source§

impl<A: Decode + Terminated, B: Decode + Terminated, C: Decode + Terminated, D: Decode + Terminated, E: Decode + Terminated, F: Decode + Terminated, G: Decode + Terminated, H: Decode + Terminated, I: Decode> Decode for (A, B, C, D, E, F, G, H, I)

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Decodes the fields of the tuple one after another, in order.

Source§

fn decode_into<R: Read>(&mut self, input: R) -> Result<()>

Decodes the fields of the tuple one after another, in order.

Recursively calls decode_into for each field.

Source§

impl<A: Decode + Terminated, B: Decode + Terminated, C: Decode + Terminated, D: Decode + Terminated, E: Decode + Terminated, F: Decode + Terminated, G: Decode + Terminated, H: Decode> Decode for (A, B, C, D, E, F, G, H)

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Decodes the fields of the tuple one after another, in order.

Source§

fn decode_into<R: Read>(&mut self, input: R) -> Result<()>

Decodes the fields of the tuple one after another, in order.

Recursively calls decode_into for each field.

Source§

impl<A: Decode + Terminated, B: Decode + Terminated, C: Decode + Terminated, D: Decode + Terminated, E: Decode + Terminated, F: Decode + Terminated, G: Decode> Decode for (A, B, C, D, E, F, G)

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Decodes the fields of the tuple one after another, in order.

Source§

fn decode_into<R: Read>(&mut self, input: R) -> Result<()>

Decodes the fields of the tuple one after another, in order.

Recursively calls decode_into for each field.

Source§

impl<A: Decode + Terminated, B: Decode + Terminated, C: Decode + Terminated, D: Decode + Terminated, E: Decode + Terminated, F: Decode> Decode for (A, B, C, D, E, F)

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Decodes the fields of the tuple one after another, in order.

Source§

fn decode_into<R: Read>(&mut self, input: R) -> Result<()>

Decodes the fields of the tuple one after another, in order.

Recursively calls decode_into for each field.

Source§

impl<A: Decode + Terminated, B: Decode + Terminated, C: Decode + Terminated, D: Decode + Terminated, E: Decode> Decode for (A, B, C, D, E)

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Decodes the fields of the tuple one after another, in order.

Source§

fn decode_into<R: Read>(&mut self, input: R) -> Result<()>

Decodes the fields of the tuple one after another, in order.

Recursively calls decode_into for each field.

Source§

impl<A: Decode + Terminated, B: Decode + Terminated, C: Decode + Terminated, D: Decode> Decode for (A, B, C, D)

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Decodes the fields of the tuple one after another, in order.

Source§

fn decode_into<R: Read>(&mut self, input: R) -> Result<()>

Decodes the fields of the tuple one after another, in order.

Recursively calls decode_into for each field.

Source§

impl<A: Decode + Terminated, B: Decode + Terminated, C: Decode> Decode for (A, B, C)

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Decodes the fields of the tuple one after another, in order.

Source§

fn decode_into<R: Read>(&mut self, input: R) -> Result<()>

Decodes the fields of the tuple one after another, in order.

Recursively calls decode_into for each field.

Source§

impl<A: Decode + Terminated, B: Decode> Decode for (A, B)

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Decodes the fields of the tuple one after another, in order.

Source§

fn decode_into<R: Read>(&mut self, input: R) -> Result<()>

Decodes the fields of the tuple one after another, in order.

Recursively calls decode_into for each field.

Source§

impl<A: Decode> Decode for (A,)

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Decodes the fields of the tuple one after another, in order.

Source§

fn decode_into<R: Read>(&mut self, input: R) -> Result<()>

Decodes the fields of the tuple one after another, in order.

Recursively calls decode_into for each field.

Source§

impl<T> Decode for PhantomData<T>

Source§

fn decode<R: Read>(_: R) -> Result<Self>

Returns a PhantomData without reading any bytes.

Source§

impl<T: Decode + Terminated> Decode for Vec<T>

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Decodes the elements of the vector one after another, in order.

Source§

fn decode_into<R: Read>(&mut self, input: R) -> Result<()>

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

Recursively calls decode_into for each element.

Source§

impl<T: Decode + Terminated, const N: usize> Decode for [T; N]

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Source§

fn decode_into<R: Read>(&mut self, input: R) -> Result<()>

Source§

impl<T: Decode> Decode for Option<T>

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Decodes a 0 byte as None, or a 1 byte followed by the encoding of the inner value as Some. Errors for all other values.

Source§

fn decode_into<R: Read>(&mut self, input: R) -> Result<()>

Decodes a 0 byte as None, or a 1 byte followed by the encoding of the inner value as Some. Errors for all other values.

Source§

impl<T: Decode> Decode for Box<T>

Source§

fn decode<R: Read>(input: R) -> Result<Self>

Decodes the inner value into a new Box.

Source§

fn decode_into<R: Read>(&mut self, input: R) -> Result<()>

Decodes the inner value into the existing Box.

Recursively calls decode_into on the inner value.

Implementors§