#type #repr #type-safe #transmute #attributes #replace #typic

macro typic-derive

Type-safe transmutations between layout-compatible types

5 unstable releases

0.3.0 Jun 30, 2020
0.2.2 Feb 7, 2020
0.2.1 Feb 7, 2020
0.2.0 Feb 6, 2020
0.1.0 Dec 28, 2019

#24 in #transmute


Used in typic

MIT/Apache

10KB
231 lines

Typic

Typic helps you transmute fearlessly. It worries about the subtleties of soundness and safety so you don't have to!

Documentation Crates.io

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!

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~1.5MB
~34K SLoC