Trait WritesEncodable

Source
pub trait WritesEncodable: Writes {
    // Provided method
    fn write_data<T: Encodable + ?Sized>(
        &mut self,
        data: &T,
    ) -> Result<(), CodecError> { ... }
}
Expand description

A thing that Writes Encodable data.


let data = Text::from("cupcakes!");

// Encode data into a vector.
let mut encoded = vec![];
encoded.write_data(&data).unwrap();

// Decode the data.
let decoded_data: Text = encoded.as_slice().read_data().unwrap();

assert_eq!(data, decoded_data);

This trait is automatically implemented for any type that Writes.

Provided Methods§

Source

fn write_data<T: Encodable + ?Sized>( &mut self, data: &T, ) -> Result<(), CodecError>

Encodes and writes a sequence of data from data.

This function will attempt to encode and write a DataHeader if the data’s Format::is_structured.

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.

Implementors§