pub trait Writer {
// Required method
fn write(&self, buf: &mut ByteWriter) -> Result<(), Error>;
// Provided method
fn write_to_bytes(&self) -> Result<ByteWriter, Error> { ... }
}
Expand description
Allows you to write to a ByteWriter
without needing to know the type.
ⓘ
use binary_util::io::{ByteWriter, Writer};
pub struct MyStruct {
pub a: u8,
pub b: u8
}
impl Writer for MyStruct {
fn write(&self, buf: &mut ByteWriter) -> Result<(), std::io::Error> {
buf.write_u8(self.a)?;
buf.write_u8(self.b)?;
Ok(());
}
}
Required Methods§
Provided Methods§
Sourcefn write_to_bytes(&self) -> Result<ByteWriter, Error>
fn write_to_bytes(&self) -> Result<ByteWriter, Error>
This is a utility function to write Self
to a ByteWriter
without
needing to create a ByteWriter
first.