pub trait BinRead: Sized {
type Args<'a>;
// Required method
fn read_options<R: Read + Seek>(
reader: &mut R,
endian: Endian,
args: Self::Args<'_>
) -> BinResult<Self>;
// Provided methods
fn read<R: Read + Seek>(reader: &mut R) -> BinResult<Self>
where Self: ReadEndian,
for<'a> Self::Args<'a>: Required { ... }
fn read_be<R: Read + Seek>(reader: &mut R) -> BinResult<Self>
where for<'a> Self::Args<'a>: Required { ... }
fn read_le<R: Read + Seek>(reader: &mut R) -> BinResult<Self>
where for<'a> Self::Args<'a>: Required { ... }
fn read_ne<R: Read + Seek>(reader: &mut R) -> BinResult<Self>
where for<'a> Self::Args<'a>: Required { ... }
fn read_args<R: Read + Seek>(
reader: &mut R,
args: Self::Args<'_>
) -> BinResult<Self>
where Self: ReadEndian { ... }
fn read_be_args<R: Read + Seek>(
reader: &mut R,
args: Self::Args<'_>
) -> BinResult<Self> { ... }
fn read_le_args<R: Read + Seek>(
reader: &mut R,
args: Self::Args<'_>
) -> BinResult<Self> { ... }
fn read_ne_args<R: Read + Seek>(
reader: &mut R,
args: Self::Args<'_>
) -> BinResult<Self> { ... }
}
Expand description
The BinRead
trait reads data from streams and converts it into objects.
This trait is usually derived, but can also be manually implemented by
writing an appropriate Args
type and read_options()
function.
Derivable
This trait can be used with #[derive]
or #[binread]
. Each field of a
derived type must either implement BinRead
or be annotated with an
attribute containing a map
, try_map
, or parse_with
directive.
Using #[binread]
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 read_args()
and
read_options()
.
When the given type implements Default
, convenience functions like
read()
are enabled. BinRead
implementations that don’t receive any
arguments should use the ()
type.
When BinRead
is derived, the import
and import_tuple
directives define this type.