SHARE
TWEET

Untitled

a guest Sep 24th, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use std::mem::size_of;
  2.  
  3. struct Coll<T> {
  4.     first: T,
  5.     second: Option<T>,
  6. }
  7.  
  8. enum CollEnum<T> {
  9.     F { first: T },
  10.     S { first: T, second: T },
  11. }
  12.  
  13. fn main() {
  14.     println!(
  15.         "|Coll<usize>| = {}, |CollEnum<usize>| = {}",
  16.         size_of::<Coll<usize>>(),
  17.         size_of::<CollEnum<usize>>()
  18.     );
  19.     // |Coll<usize>| = 24, |CollEnum<usize>| = 24
  20.    
  21.     println!(
  22.         "|Coll<Option<usize>>| = {}, |CollEnum<Option<usize>>| = {}",
  23.         size_of::<Coll<Option<usize>>>(),
  24.         size_of::<CollEnum<Option<usize>>>()
  25.     );
  26.     // |Coll<Option<usize>>| = 32, |CollEnum<Option<usize>>| = 40
  27.    
  28.     println!(
  29.         "|Coll<Option<Option<usize>>>| = {}, |CollEnum<Option<Option<usize>>>| = {}",
  30.         size_of::<Coll<Option<Option<usize>>>>(),
  31.         size_of::<CollEnum<Option<Option<usize>>>>()
  32.     );
  33.     // |Coll<Option<Option<usize>>>| = 32, |CollEnum<Option<Option<usize>>>| = 40
  34. }
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