Building Plain Old Data from Scratch
2024-06-06I made an interesting discovery in Rust last weekend while messing with postcard:
enum
s are the only "plain" data type (I'm aware of) in Rust that you can't build "from scratch".
When I say "from scratch", I mean using unsafe methods to manually initialize each field,
say in a MaybeUninit
, then call assume_init()
.
There are other "complex" data types, like trait objects, you can't necessarily build from scratch, but these are rarely relevant when serializing and deserializing. Even items on the heap can generally be built "in place" using various unsafe methods.