BinWriterExt

Trait BinWriterExt 

Source
pub trait BinWriterExt:
    Write
    + Seek
    + Sized {
    // Provided methods
    fn write_type<T: BinWrite>(
        &mut self,
        value: &T,
        endian: Endian,
    ) -> BinResult<()>
       where for<'a> T::Args<'a>: Required { ... }
    fn write_be<T: BinWrite>(&mut self, value: &T) -> BinResult<()>
       where for<'a> T::Args<'a>: Required { ... }
    fn write_le<T: BinWrite>(&mut self, value: &T) -> BinResult<()>
       where for<'a> T::Args<'a>: Required { ... }
    fn write_ne<T: BinWrite>(&mut self, value: &T) -> BinResult<()>
       where for<'a> T::Args<'a>: Required { ... }
    fn write_type_args<T: BinWrite>(
        &mut self,
        value: &T,
        endian: Endian,
        args: T::Args<'_>,
    ) -> BinResult<()> { ... }
    fn write_be_args<T: BinWrite>(
        &mut self,
        value: &T,
        args: T::Args<'_>,
    ) -> BinResult<()> { ... }
    fn write_le_args<T: BinWrite>(
        &mut self,
        value: &T,
        args: T::Args<'_>,
    ) -> BinResult<()> { ... }
    fn write_ne_args<T: BinWrite>(
        &mut self,
        value: &T,
        args: T::Args<'_>,
    ) -> BinResult<()> { ... }
}
Expand description

Extension methods for writing BinWrite objects directly to a writer.

§Examples

use binrw::{binwrite, BinWriterExt, io::Cursor, Endian};

#[binwrite]
struct MyStruct(u8, u16, u8);

let mut writer = Cursor::new(Vec::new());
writer.write_be(&MyStruct(1, 0xffff, 2)).unwrap();
writer.write_type(&0x1234_u16, Endian::Little).unwrap();

assert_eq!(writer.into_inner(), [1, 0xff, 0xff, 2, 0x34, 0x12]);

Provided Methods§

Source

fn write_type<T: BinWrite>( &mut self, value: &T, endian: Endian, ) -> BinResult<()>
where for<'a> T::Args<'a>: Required,

Write T to the writer with the given byte order.

§Errors

If writing fails, an Error variant will be returned.

Source

fn write_be<T: BinWrite>(&mut self, value: &T) -> BinResult<()>
where for<'a> T::Args<'a>: Required,

Write T to the writer assuming big-endian byte order.

§Errors

If writing fails, an Error variant will be returned.

Source

fn write_le<T: BinWrite>(&mut self, value: &T) -> BinResult<()>
where for<'a> T::Args<'a>: Required,

Write T to the writer assuming little-endian byte order.

§Errors

If writing fails, an Error variant will be returned.

Source

fn write_ne<T: BinWrite>(&mut self, value: &T) -> BinResult<()>
where for<'a> T::Args<'a>: Required,

Write T to the writer assuming native-endian byte order.

§Errors

If writing fails, an Error variant will be returned.

Source

fn write_type_args<T: BinWrite>( &mut self, value: &T, endian: Endian, args: T::Args<'_>, ) -> BinResult<()>

Write T to the writer with the given byte order and arguments.

§Errors

If writing fails, an Error variant will be returned.

Source

fn write_be_args<T: BinWrite>( &mut self, value: &T, args: T::Args<'_>, ) -> BinResult<()>

Write T to the writer, assuming big-endian byte order, using the given arguments.

§Errors

If writing fails, an Error variant will be returned.

Source

fn write_le_args<T: BinWrite>( &mut self, value: &T, args: T::Args<'_>, ) -> BinResult<()>

Write T to the writer, assuming little-endian byte order, using the given arguments.

§Errors

If writing fails, an Error variant will be returned.

Source

fn write_ne_args<T: BinWrite>( &mut self, value: &T, args: T::Args<'_>, ) -> BinResult<()>

Write T to the writer, assuming native-endian byte order, using the given arguments.

§Errors

If writing fails, an Error variant will be returned.

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§