map_struct
A rust library to map raw data to a struct.
Usage
In Cargo.toml
,
[]
= "0.3"
Implement unsafe Mappable
trait to the struct to be mapped to a raw data:
unsafe
Call mapped
:
// mapped returns Option<(&Self, &[u8])>
mapped
mapped
returns None
if the argument length is not enough for the struct.
It otherwise returns the tuple of the reference to the mapped struct and the rest of the data.
For &mut [u8]
, we may also use mapped_mut
, which returns Option<(&mut Self, &mut [u8])>
instead.
We also provide a inverse method of mapped
, as_bytes
. The usage is following.
let hoge = mapped.unwrap.0;
assert!;