Typic
Type-safe transmutations between layout-compatible types.
Install / Use
/learn @jswrenn/TypicREADME
ANNOUNCEMENT: The primary purpose of Typic was to prototype zero-compromise designs for a safe transmute language feature. Read the resulting RFC draft here!
Typic
Typic helps you transmute fearlessly. It worries about the subtleties of soundness and safety so you don't have to!
Just import it and replace your #[repr(...)] attributes with #[typic::repr(...)]:
// Import it!
use typic::{self, TransmuteInto};
// Update your attributes!
#[typic::repr(C)]
pub struct Foo(pub u8, pub u16);
// Transmute fearlessly!
let _ : Foo = u32::default().transmute_into(); // Alchemy achieved!
let _ : u32 = Foo::default().transmute_into(); // Compiler Error!
