pub trait DeBin: Sized {
// Required method
fn de_bin(offset: &mut usize, bytes: &[u8]) -> Result<Self, DeBinErr>;
// Provided method
fn deserialize_bin(d: &[u8]) -> Result<Self, DeBinErr> { ... }
}
Expand description
A trait for objects that can be deserialized from binary.
Required Methods§
sourcefn de_bin(offset: &mut usize, bytes: &[u8]) -> Result<Self, DeBinErr>
fn de_bin(offset: &mut usize, bytes: &[u8]) -> Result<Self, DeBinErr>
Parse Self from the input bytes starting at index offset
.
After deserialization, offset
is updated to point at the byte after
the last one used.
let bytes = [1, 0, 0, 0, 2, 0, 0, 0];
let mut offset = 4;
let two = u32::de_bin(&mut offset, &bytes).unwrap();
assert_eq!(two, 2);
assert_eq!(offset, 8);
Provided Methods§
sourcefn deserialize_bin(d: &[u8]) -> Result<Self, DeBinErr>
fn deserialize_bin(d: &[u8]) -> Result<Self, DeBinErr>
Parse Self from the input bytes.
This is a convenient wrapper around de_bin
.
Object Safety§
This trait is not object safe.