Comment by whytevuhuni
4 days ago
This is generally unsafe, so to make it safe there needs to be something that restricts what kind of things you can read and write.
For example, if your structure contains a reference, and you read an instance of that from disk, then you now have a potentially invalid reference, bypassing Rust's guarantees. Reading a structure of i32 numbers is safe, but it also has endianness footguns.
The zerocopy crate implements traits and gives you a derive macro to mark types as being safe to serialize/deserialize in a safe way.
No comments yet
Contribute on Hacker News ↗