Skip to content

Instantly share code, notes, and snippets.

@rrichardson
Created December 31, 2014 22:51
Show Gist options
  • Save rrichardson/24fcd70dc3f5924a901b to your computer and use it in GitHub Desktop.
Save rrichardson/24fcd70dc3f5924a901b to your computer and use it in GitHub Desktop.
unsafe fn struct_to_bytes<T>(t: &T) -> &[u8] {
mem::transmute(raw::Slice::<u8> {
data: t as *const T as *const u8,
len: mem::size_of::<T>(),
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment