Skip to main content

SerWrite

Trait SerWrite 

Source
pub trait SerWrite {
    type Error;

    // Required method
    fn write(&mut self, buf: &[u8]) -> Result<(), Self::Error>;

    // Provided methods
    fn write_byte(&mut self, byte: u8) -> Result<(), Self::Error> { ... }
    fn write_str(&mut self, s: &str) -> Result<(), Self::Error> { ... }
}
Expand description

Serializers should write data to the implementations of this trait.

Required Associated Types§

Source

type Error

An error type returned from the trait methods.

Required Methods§

Source

fn write(&mut self, buf: &[u8]) -> Result<(), Self::Error>

Write all bytes from buf to the internal buffer.

Otherwise return an error.

Provided Methods§

Source

fn write_byte(&mut self, byte: u8) -> Result<(), Self::Error>

Write a single byte to the internal buffer.

Return an error if the operation could not succeed.

Source

fn write_str(&mut self, s: &str) -> Result<(), Self::Error>

Write a whole string to the internal buffer.

Otherwise return an error.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl SerWrite for Vec<u8>

Available on crate features alloc or std only.
Source§

type Error = SerError

Source§

fn write(&mut self, buf: &[u8]) -> Result<(), SerError>

Source§

fn write_byte(&mut self, byte: u8) -> Result<(), SerError>

Source§

impl SerWrite for VecDeque<u8>

Available on crate features alloc or std only.
Source§

type Error = SerError

Source§

fn write(&mut self, buf: &[u8]) -> Result<(), SerError>

Source§

fn write_byte(&mut self, byte: u8) -> Result<(), SerError>

Source§

impl<T> SerWrite for &mut T
where T: SerWrite,

Source§

type Error = <T as SerWrite>::Error

Source§

fn write(&mut self, buf: &[u8]) -> Result<(), <&mut T as SerWrite>::Error>

Source§

fn write_byte(&mut self, byte: u8) -> Result<(), <&mut T as SerWrite>::Error>

Source§

fn write_str(&mut self, s: &str) -> Result<(), <&mut T as SerWrite>::Error>

Source§

impl<T> SerWrite for Cursor<T>
where Cursor<T>: Write,

Available on crate feature std only.
Source§

type Error = SerError

Source§

fn write(&mut self, buf: &[u8]) -> Result<(), SerError>

Implementors§