Trait recode::Encoder

source ·
pub trait Encoder<Item = Self> {
    type Error;

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

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

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 BytesMut) -> Result<(), Self::Error>

Encodes the given input into the output buffer.

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

fn size_of(item: &Item) -> 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.

Implementations on Foreign Types§

source§

impl Encoder<u64> for u64

§

type Error = Infallible

source§

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

source§

fn size_of(_: &u64) -> usize

source§

impl Encoder<i32> for i32

§

type Error = Infallible

source§

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

source§

fn size_of(_: &i32) -> usize

source§

impl Encoder<i16> for i16

§

type Error = Infallible

source§

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

source§

fn size_of(_: &i16) -> usize

source§

impl Encoder<usize> for i16

§

type Error = Error

source§

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

source§

fn size_of(_: &usize) -> usize

source§

impl Encoder<usize> for u16

§

type Error = Error

source§

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

source§

fn size_of(_: &usize) -> usize

source§

impl Encoder<usize> for u8

§

type Error = Error

source§

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

source§

fn size_of(_: &usize) -> usize

source§

impl Encoder<i64> for i64

§

type Error = Infallible

source§

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

source§

fn size_of(_: &i64) -> usize

source§

impl Encoder<usize> for u128

§

type Error = Error

source§

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

source§

fn size_of(_: &usize) -> usize

source§

impl Encoder<usize> for u64

§

type Error = Error

source§

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

source§

fn size_of(_: &usize) -> usize

source§

impl Encoder<u32> for u32

§

type Error = Infallible

source§

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

source§

fn size_of(_: &u32) -> usize

source§

impl Encoder<usize> for i128

§

type Error = Error

source§

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

source§

fn size_of(_: &usize) -> usize

source§

impl Encoder<i128> for i128

§

type Error = Infallible

source§

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

source§

fn size_of(_: &i128) -> usize

source§

impl Encoder<u16> for u16

§

type Error = Infallible

source§

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

source§

fn size_of(_: &u16) -> usize

source§

impl Encoder<usize> for i64

§

type Error = Error

source§

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

source§

fn size_of(_: &usize) -> usize

source§

impl Encoder<usize> for i8

§

type Error = Error

source§

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

source§

fn size_of(_: &usize) -> usize

source§

impl Encoder<u128> for u128

§

type Error = Infallible

source§

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

source§

fn size_of(_: &u128) -> usize

source§

impl Encoder<usize> for i32

§

type Error = Error

source§

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

source§

fn size_of(_: &usize) -> usize

source§

impl Encoder<i8> for i8

§

type Error = Infallible

source§

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

source§

fn size_of(_: &i8) -> usize

source§

impl Encoder<u8> for u8

§

type Error = Infallible

source§

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

source§

fn size_of(_: &u8) -> usize

source§

impl Encoder<usize> for u32

§

type Error = Error

source§

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

source§

fn size_of(_: &usize) -> usize

Implementors§