A crate for safely converting arbitrary memory into Rust types.
Intro
Imagine you have an enum type, like so:
Say that you have a pointer to that enum that came from an untrusted context, like a wonky C API or from a userspace process to your kernel:
let foo: *const Foo = todo!
While pointer alignment is easy to verify, "untrusted context" means that the memory behind the pointer can be arbitrary. We can't simply convert the pointer to such memory to a reference, since this can lead to undefined behaviour.
Fortunately, the layout for properly defined #[repr(C)] types is
well-defined.
Unfortunately, working with this layout involves writing a lot of boilerplate,
especially for enums.
This crate does the boilerplate for you, like so:
use ;
use TryInto;
use transmute;
// Repr<Foo> can have any memory contents.