Trait Writer

Source
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§

Source

fn write(&self, buf: &mut ByteWriter) -> Result<(), Error>

Writes Self to a ByteWriter.

For automatic implementations, use #[derive(BinaryEncoder] macro.

Provided Methods§

Source

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.

Implementations on Foreign Types§

Source§

impl Writer for &str

Source§

fn write(&self, buf: &mut ByteWriter) -> Result<(), Error>

Source§

impl Writer for SocketAddr

Source§

fn write(&self, buf: &mut ByteWriter) -> Result<(), Error>

Source§

impl Writer for bool

Source§

fn write(&self, buf: &mut ByteWriter) -> Result<(), Error>

Source§

impl Writer for char

Source§

fn write(&self, buf: &mut ByteWriter) -> Result<(), Error>

Source§

impl Writer for f32

Source§

fn write(&self, buf: &mut ByteWriter) -> Result<(), Error>

Source§

impl Writer for f64

Source§

fn write(&self, buf: &mut ByteWriter) -> Result<(), Error>

Source§

impl Writer for i8

Source§

fn write(&self, buf: &mut ByteWriter) -> Result<(), Error>

Source§

impl Writer for i16

Source§

fn write(&self, buf: &mut ByteWriter) -> Result<(), Error>

Source§

impl Writer for i32

Source§

fn write(&self, buf: &mut ByteWriter) -> Result<(), Error>

Source§

impl Writer for i64

Source§

fn write(&self, buf: &mut ByteWriter) -> Result<(), Error>

Source§

impl Writer for i128

Source§

fn write(&self, buf: &mut ByteWriter) -> Result<(), Error>

Source§

impl Writer for u8

Source§

fn write(&self, buf: &mut ByteWriter) -> Result<(), Error>

Source§

impl Writer for u16

Source§

fn write(&self, buf: &mut ByteWriter) -> Result<(), Error>

Source§

impl Writer for u32

Source§

fn write(&self, buf: &mut ByteWriter) -> Result<(), Error>

Source§

impl Writer for u64

Source§

fn write(&self, buf: &mut ByteWriter) -> Result<(), Error>

Source§

impl Writer for u128

Source§

fn write(&self, buf: &mut ByteWriter) -> Result<(), Error>

Source§

impl Writer for String

Source§

fn write(&self, buf: &mut ByteWriter) -> Result<(), Error>

Source§

impl<T> Writer for Option<T>
where T: Writer + Sized,

Source§

fn write(&self, buf: &mut ByteWriter) -> Result<(), Error>

Source§

impl<T> Writer for Vec<T>
where T: Writer + Sized,

Source§

fn write(&self, buf: &mut ByteWriter) -> Result<(), Error>

Implementors§