SHARE
TWEET

Untitled

a guest Apr 24th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use std::mem::{transmute, size_of};
  2.  
  3. fn from_bytes<T: Copy>(bs: &[u8]) -> Option<&T> {
  4.     if bs.len() < size_of::<T>() {
  5.         None
  6.     } else {
  7.         Some(unsafe { transmute(bs as *const [u8] as *const u8) })
  8.     }
  9. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top