We have a
struct Tthat has
From just the above, can we derive
Vec<T> -> fileand
file -> Vec<T>functions?
If not, what else do we need?
You could use
slice::from_raw_parts(_mut) to cast
Vec's contents to
[u8] for purpose of I/O. Note that you can’t cast from
[T], because it doesn’t guarantee alignment.
repr(C) is still not enough to have safe and reliable file representation for any type, because pointers can be
Copy and exact size and layout of
repr(C) still varies between architectures.
The safe and reliable alternative is bincode.
Thanks, bincode works great!