Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


This 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.


RFC PR: https://github.com/rust-lang/rfcs/pull/2981

RFC text: 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/ and https://docs.rs/bytemuck/latest/bytemuck/




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: