News for hackers. Stuff that matters.
Re:Deserializing Binary Data Files in Rust by sophacles on Monday June 28, 2021 @04:13PM (#27667327)
How would it be possible to make it safe? The compiler can't verify that N random bytes input from an arbitrary source are going to be valid for the types in the struct - you have to tell tell the compiler "trust this even if you can't verify it from the source code" - hence the unsafe keyword.
Re:Deserializing Binary Data Files in Rust by Alexendoo on Monday June 28, 2021 @04:16PM (#27667396)
Re:Deserializing Binary Data Files in Rust by sophacles on Monday June 28, 2021 @10:49PM (#27671144)
Oh cool! Thanks for the pointer.
Re:Deserializing Binary Data Files in Rust by coldnose on Monday June 28, 2021 @04:26PM (#27667551)
For integer primitives, all possible values are valid. Just allowing binary initialization for structs that consist of integer types would allow compatibility with C structure. As it is, I have to either resort to unsafe code or manually deserialize every struct
Re:Deserializing Binary Data Files in Rust by sophacles on Monday June 28, 2021 @10:48PM (#27671139)
Oh I see, that makes sense. Also there's a sibling reply to yours for a cool looking proposal to do just that if you haven't seen it yet.