Guest User

Untitled

a guest
Oct 22nd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #![feature(never_type)]
  2.  
  3. use std::mem::{size_of};
  4.  
  5. #[derive(Debug, Copy, Clone)]
  6. enum Singleton { Zero }
  7.  
  8. #[derive(Debug, Copy, Clone)]
  9. enum Empty {}
  10.  
  11. fn main() {
  12. let singleton_box = Box::new(Singleton::Zero);
  13. let never_box = unsafe { std::mem::transmute::<Box<()>, Box<Empty>>(Box::new(())) };
  14. let bang_box = unsafe { std::mem::transmute::<Box<()>, Box<!>>(Box::new(())) };
  15. println!("size_of::<()> = {}", size_of::<()>());
  16. println!("size_of::<Singleton> = {}", size_of::<Singleton>());
  17. println!("size_of::<Empty> = {}", size_of::<Empty>());
  18. println!("size_of::<!> = {}", size_of::<!>());
  19. println!("value of Box<Singleton> = {:?}", singleton_box);
  20. println!("value of Box<Never> = {:?}", never_box);
  21. println!("value of Box<!> = {:?}", bang_box);
  22. }
Add Comment
Please, Sign In to add comment