pub trait BinWrite {
type Args<'a>;
// Required method
fn write_options<W: Write + Seek>(
&self,
writer: &mut W,
endian: Endian,
args: Self::Args<'_>,
) -> BinResult<()>;
// Provided methods
fn write<W: Write + Seek>(&self, writer: &mut W) -> BinResult<()>
where Self: WriteEndian,
for<'a> Self::Args<'a>: Required { ... }
fn write_be<W: Write + Seek>(&self, writer: &mut W) -> BinResult<()>
where for<'a> Self::Args<'a>: Required { ... }
fn write_le<W: Write + Seek>(&self, writer: &mut W) -> BinResult<()>
where for<'a> Self::Args<'a>: Required { ... }
fn write_args<W: Write + Seek>(
&self,
writer: &mut W,
args: Self::Args<'_>,
) -> BinResult<()>
where Self: WriteEndian { ... }
fn write_be_args<W: Write + Seek>(
&self,
writer: &mut W,
args: Self::Args<'_>,
) -> BinResult<()> { ... }
fn write_le_args<W: Write + Seek>(
&self,
writer: &mut W,
args: Self::Args<'_>,
) -> BinResult<()> { ... }
}
Expand description
The BinWrite
trait serialises objects and writes them to streams.
This trait is usually derived, but can also be manually implemented by
writing an appropriate Args
type and write_options()
function.
§Derivable
This trait can be used with #[derive]
or #[binwrite]
. Each field
of a derived type must either implement BinWrite
or be annotated with an
attribute containing a map
, try_map
, or write_with
directive.
Using #[binwrite]
instead of #[derive]
is required when using
temporary fields.
Required Associated Types§
sourcetype Args<'a>
type Args<'a>
The type used for the args
parameter of write_args()
and
write_options()
.
When the given type implements Default
, convenience functions like
write()
are enabled. BinWrite
implementations that don’t
receive any arguments should use the ()
type.
When BinWrite
is derived, the import
and import_tuple
directives define this type.