Trait binout::Serializer

source ·
pub trait Serializer<T: Copy>: Copy {
    const CONST_SIZE: Option<usize> = None;

    // Required methods
    fn size(val: T) -> usize;
    fn write<W: Write + ?Sized>(output: &mut W, val: T) -> Result<()>;
    fn read<R: Read + ?Sized>(input: &mut R) -> Result<T>;

    // Provided methods
    fn write_all_values<W, InIter>(output: &mut W, values: InIter) -> Result<()>
       where W: Write + ?Sized,
             InIter: IntoIterator<Item = T> { ... }
    fn write_all<'a, W, InIter>(output: &mut W, values: InIter) -> Result<()>
       where W: Write + ?Sized,
             InIter: IntoIterator<Item = &'a T>,
             T: 'a { ... }
    fn array_content_size(array: &[T]) -> usize { ... }
    fn array_size(array: &[T]) -> usize { ... }
    fn write_array<W: Write + ?Sized>(output: &mut W, array: &[T]) -> Result<()> { ... }
    fn read_n<R: Read + ?Sized>(input: &mut R, n: usize) -> Result<Box<[T]>> { ... }
    fn read_array<R: Read + ?Sized>(input: &mut R) -> Result<Box<[T]>> { ... }
}
Expand description

Trait implemented by each serializer for the following types: u8, u16, u32, u64, usize (which, for portability, is always serialized the same as u64).

Provided Associated Constants§

source

const CONST_SIZE: Option<usize> = None

Either size of each value in bytes (if each value occupies constant size) or None.

Required Methods§

source

fn size(val: T) -> usize

Returns number of bytes which write needs to serialize val.

source

fn write<W: Write + ?Sized>(output: &mut W, val: T) -> Result<()>

Serialize val to the given output.

source

fn read<R: Read + ?Sized>(input: &mut R) -> Result<T>

Deserialize value from the given input.

Provided Methods§

source

fn write_all_values<W, InIter>(output: &mut W, values: InIter) -> Result<()>
where W: Write + ?Sized, InIter: IntoIterator<Item = T>,

Serialize all values into the given output.

source

fn write_all<'a, W, InIter>(output: &mut W, values: InIter) -> Result<()>
where W: Write + ?Sized, InIter: IntoIterator<Item = &'a T>, T: 'a,

Serialize all values into the given output.

source

fn array_content_size(array: &[T]) -> usize

Returns number of bytes occupied by serialized content of the array.

source

fn array_size(array: &[T]) -> usize

Returns number of bytes which write_array needs to serialize array.

source

fn write_array<W: Write + ?Sized>(output: &mut W, array: &[T]) -> Result<()>

Serialize array to the given input. Size of the array is serialized in VByte format.

source

fn read_n<R: Read + ?Sized>(input: &mut R, n: usize) -> Result<Box<[T]>>

Deserialize n values from the given input.

source

fn read_array<R: Read + ?Sized>(input: &mut R) -> Result<Box<[T]>>

Deserialize array from the given input. Size of the array is serialized in VByte format.

Object Safety§

This trait is not object safe.

Implementors§