7 ms·
I believe there is a group working on "safe transmute", which would address the newtype issues... safely. Not just memory safety, but invariant safe, to prevent
by swsieber 4y ago
I believe there is a group working on "safe transmute", which would address the newtype issues... safely. Not just memory safety, but invariant safe, to prevent transmutes in safe rust when the newtype wrapper wants to protect its own invariants.
- shirogane86x 4y agoThis sounds really interesting (and also eerily similar to haskell's Coercible and roles), is there any material on the matter somewhere? I'd love to see what solution they're thinking of working towards, seeing as this is a pain point that I encounter somewhat frequently.
- burntsushi 4y agoRFC PR: https://github.com/rust-lang/rfcs/pull/2981 https://github.com/rust-lang/rfcs/pull/2981 RFC text: https://github.com/jswrenn/rfcs/blob/safer-transmute/text/0000-safer-transmute.md https://github.com/jswrenn/rfcs/blob/safer-transmute/text/00... I don't know what the status quo is, but it is very exciting work. There are also crates in this domain that work today. The two I'm aware of are https://docs.rs/zerocopy/latest/zerocopy/ https://docs.rs/zerocopy/latest/zerocopy/ and https://docs.rs/bytemuck/latest/bytemuck/ https://docs.rs/bytemuck/latest/bytemuck/