as_with_bytes
Simple serialization for simple values.
Using these traits, values can be serialized as bytes without any copying of data whatsoever.
Implementations
AsBytes
, WithBytes
, and TryWithBytes
are all implemented for types T
and [T]
where T: Copy
.
try_with_bytes
always returns Some(&[T])
when used on a dynamically sized slice, although the slice
referenced can be empty. The trait is only implemented there for genericity.
Examples
let n: u32 = 0;
assert_eq!;
It's all the same block of memory
use ptr;
let arr = ;
// They reference the same memory address
assert!;