pub trait DataFormat: Sized {
type Header: DataFormat + Clone;
const LATEST_HEADER: Self::Header;
// Required methods
fn write_data<W: Write>(
&self,
writer: &mut W,
) -> Result<usize, DataWriteError>;
fn read_data<R: Read>(
reader: &mut R,
header: &Self::Header,
) -> Result<Self, DataReadError>;
// Provided methods
fn write_header<W: Write>(
&self,
writer: &mut W,
) -> Result<usize, DataWriteError> { ... }
fn read_header<R: Read>(
reader: &mut R,
) -> Result<Self::Header, DataReadError> { ... }
fn to_byte_vec(&self) -> Result<Vec<u8>, DataWriteError> { ... }
}Expand description
DataFormat is a trait for serializing and deserializing binary data.
A header is read/written containing the versions of the desired data
Required Associated Constants§
const LATEST_HEADER: Self::Header
Required Associated Types§
type Header: DataFormat + Clone
Required Methods§
Sourcefn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>
fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>
Write the data to the writer
Provided Methods§
fn write_header<W: Write>( &self, writer: &mut W, ) -> Result<usize, DataWriteError>
fn read_header<R: Read>(reader: &mut R) -> Result<Self::Header, DataReadError>
Sourcefn to_byte_vec(&self) -> Result<Vec<u8>, DataWriteError>
fn to_byte_vec(&self) -> Result<Vec<u8>, DataWriteError>
Convert the data to a byte vector
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.