Trait Serialize

Source
pub trait Serialize: ByteSize {
    // Required method
    fn write_to(&self, writer: &mut BytesMut);

    // Provided method
    fn write_to_end(&self, writer: &mut BytesMut) { ... }
}
Expand description

The Serialize trait allows an item to be serialized into a binary representation of itself, which may then be used send it off over the network. This trait requires the ByteSize trait to also be present in order to pre-allocate the necessary amount of space for the serialized data.

Serialize only provides one method: Serialize::write_to. This method is used to serialize the data and write it into the given buffer. This buffer may already contain data unrelated to this item and may have more space available for more items to follow. However, it is always at least the size provided by ByteSize.

Required Methods§

Source

fn write_to(&self, writer: &mut BytesMut)

Writes all bytes representing the content of the struct to the writer output.

Provided Methods§

Source

fn write_to_end(&self, writer: &mut BytesMut)

Convenience around [self.write_to] which already reserves the necessary space.

Implementations on Foreign Types§

Source§

impl Serialize for bool

Source§

fn write_to(&self, writer: &mut BytesMut)

Source§

impl Serialize for f32

Source§

fn write_to(&self, writer: &mut BytesMut)

Source§

impl Serialize for f64

Source§

fn write_to(&self, writer: &mut BytesMut)

Source§

impl Serialize for i16

Source§

fn write_to(&self, writer: &mut BytesMut)

Source§

impl Serialize for i32

Source§

fn write_to(&self, writer: &mut BytesMut)

Source§

impl Serialize for i64

Source§

fn write_to(&self, writer: &mut BytesMut)

Source§

impl Serialize for u8

Source§

fn write_to(&self, writer: &mut BytesMut)

Source§

impl Serialize for u16

Source§

fn write_to(&self, writer: &mut BytesMut)

Source§

impl Serialize for u32

Source§

fn write_to(&self, writer: &mut BytesMut)

Source§

impl Serialize for u64

Source§

fn write_to(&self, writer: &mut BytesMut)

Source§

impl<T: TimeZone> Serialize for DateTime<T>

Source§

fn write_to(&self, writer: &mut BytesMut)

Implementors§