Encoder

Trait Encoder 

Source
pub trait Encoder<B, Item = Self> {
    type Error;

    // Required methods
    fn encode(item: &Item, buf: &mut B) -> Result<(), Self::Error>;
    fn size_of(item: &Item, buf: &B) -> usize;
}
Expand description

A trait to be implemented by types that encode [Item] values into a buffer of type [B].

Required Associated Types§

Source

type Error

The type of error that can occur if encoding fails.

Required Methods§

Source

fn encode(item: &Item, buf: &mut B) -> Result<(), Self::Error>

Encodes the given input into the output buffer.

This method does not return a result because calls to Encoder::encode never do.

§Arguments
  • item - The input to encode.
  • buf - The output buffer to write the encoded input to.
Source

fn size_of(item: &Item, buf: &B) -> usize

Returns the number of bytes required to encode the given input.

This method is useful for pre-allocating buffers that will be used for encoding.

§Arguments
  • item - The input to encode.
  • buf - The output buffer used for encoding.
§Returns

The number of bytes required to encode the given input.

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<B: BufMut> Encoder<B> for i8

Source§

type Error = Infallible

Source§

fn encode(item: &i8, buf: &mut B) -> Result<(), Self::Error>

Source§

fn size_of(_: &i8, _: &B) -> usize

Source§

impl<B: BufMut> Encoder<B> for i16

Source§

type Error = Infallible

Source§

fn encode(item: &i16, buf: &mut B) -> Result<(), Self::Error>

Source§

fn size_of(_: &i16, _: &B) -> usize

Source§

impl<B: BufMut> Encoder<B> for i32

Source§

type Error = Infallible

Source§

fn encode(item: &i32, buf: &mut B) -> Result<(), Self::Error>

Source§

fn size_of(_: &i32, _: &B) -> usize

Source§

impl<B: BufMut> Encoder<B> for i64

Source§

type Error = Infallible

Source§

fn encode(item: &i64, buf: &mut B) -> Result<(), Self::Error>

Source§

fn size_of(_: &i64, _: &B) -> usize

Source§

impl<B: BufMut> Encoder<B> for i128

Source§

type Error = Infallible

Source§

fn encode(item: &i128, buf: &mut B) -> Result<(), Self::Error>

Source§

fn size_of(_: &i128, _: &B) -> usize

Source§

impl<B: BufMut> Encoder<B> for u8

Source§

type Error = Infallible

Source§

fn encode(item: &u8, buf: &mut B) -> Result<(), Self::Error>

Source§

fn size_of(_: &u8, _: &B) -> usize

Source§

impl<B: BufMut> Encoder<B> for u16

Source§

type Error = Infallible

Source§

fn encode(item: &u16, buf: &mut B) -> Result<(), Self::Error>

Source§

fn size_of(_: &u16, _: &B) -> usize

Source§

impl<B: BufMut> Encoder<B> for u32

Source§

type Error = Infallible

Source§

fn encode(item: &u32, buf: &mut B) -> Result<(), Self::Error>

Source§

fn size_of(_: &u32, _: &B) -> usize

Source§

impl<B: BufMut> Encoder<B> for u64

Source§

type Error = Infallible

Source§

fn encode(item: &u64, buf: &mut B) -> Result<(), Self::Error>

Source§

fn size_of(_: &u64, _: &B) -> usize

Source§

impl<B: BufMut> Encoder<B> for u128

Source§

type Error = Infallible

Source§

fn encode(item: &u128, buf: &mut B) -> Result<(), Self::Error>

Source§

fn size_of(_: &u128, _: &B) -> usize

Source§

impl<B: BufMut> Encoder<B, usize> for i8

Source§

type Error = Error

Source§

fn encode(item: &usize, buf: &mut B) -> Result<(), Self::Error>

Source§

fn size_of(_: &usize, _: &B) -> usize

Source§

impl<B: BufMut> Encoder<B, usize> for i16

Source§

type Error = Error

Source§

fn encode(item: &usize, buf: &mut B) -> Result<(), Self::Error>

Source§

fn size_of(_: &usize, _: &B) -> usize

Source§

impl<B: BufMut> Encoder<B, usize> for i32

Source§

type Error = Error

Source§

fn encode(item: &usize, buf: &mut B) -> Result<(), Self::Error>

Source§

fn size_of(_: &usize, _: &B) -> usize

Source§

impl<B: BufMut> Encoder<B, usize> for i64

Source§

type Error = Error

Source§

fn encode(item: &usize, buf: &mut B) -> Result<(), Self::Error>

Source§

fn size_of(_: &usize, _: &B) -> usize

Source§

impl<B: BufMut> Encoder<B, usize> for i128

Source§

type Error = Error

Source§

fn encode(item: &usize, buf: &mut B) -> Result<(), Self::Error>

Source§

fn size_of(_: &usize, _: &B) -> usize

Source§

impl<B: BufMut> Encoder<B, usize> for u8

Source§

type Error = Error

Source§

fn encode(item: &usize, buf: &mut B) -> Result<(), Self::Error>

Source§

fn size_of(_: &usize, _: &B) -> usize

Source§

impl<B: BufMut> Encoder<B, usize> for u16

Source§

type Error = Error

Source§

fn encode(item: &usize, buf: &mut B) -> Result<(), Self::Error>

Source§

fn size_of(_: &usize, _: &B) -> usize

Source§

impl<B: BufMut> Encoder<B, usize> for u32

Source§

type Error = Error

Source§

fn encode(item: &usize, buf: &mut B) -> Result<(), Self::Error>

Source§

fn size_of(_: &usize, _: &B) -> usize

Source§

impl<B: BufMut> Encoder<B, usize> for u64

Source§

type Error = Error

Source§

fn encode(item: &usize, buf: &mut B) -> Result<(), Self::Error>

Source§

fn size_of(_: &usize, _: &B) -> usize

Source§

impl<B: BufMut> Encoder<B, usize> for u128

Source§

type Error = Error

Source§

fn encode(item: &usize, buf: &mut B) -> Result<(), Self::Error>

Source§

fn size_of(_: &usize, _: &B) -> usize

Implementors§

Source§

impl<B> Encoder<B, usize> for Remaining

Source§

impl<B, L> Encoder<B> for Ascii<L>
where Buffer<L>: Encoder<B>, Error: From<<Buffer<L> as Encoder<B>>::Error>,

Source§

impl<B, L> Encoder<B> for Buffer<L>
where B: BufMut, L: Encoder<B, usize>, Error: From<<L as Encoder<B, usize>>::Error>,

Source§

impl<B, L> Encoder<B> for Utf8<L>
where Buffer<L>: Encoder<B>, Error: From<<Buffer<L> as Encoder<B>>::Error>,

Source§

impl<B: BufMut> Encoder<B> for i24

Source§

impl<B: BufMut> Encoder<B> for i40

Source§

impl<B: BufMut> Encoder<B> for i48

Source§

impl<B: BufMut> Encoder<B> for i56

Source§

impl<B: BufMut> Encoder<B> for u24

Source§

impl<B: BufMut> Encoder<B> for u40

Source§

impl<B: BufMut> Encoder<B> for u48

Source§

impl<B: BufMut> Encoder<B> for u56

Source§

impl<B: BufMut> Encoder<B, usize> for i24

Source§

impl<B: BufMut> Encoder<B, usize> for i40

Source§

impl<B: BufMut> Encoder<B, usize> for i48

Source§

impl<B: BufMut> Encoder<B, usize> for i56

Source§

impl<B: BufMut> Encoder<B, usize> for u24

Source§

impl<B: BufMut> Encoder<B, usize> for u40

Source§

impl<B: BufMut> Encoder<B, usize> for u48

Source§

impl<B: BufMut> Encoder<B, usize> for u56