doc.rust-lang.org/std/mem/fn.size_of.html
Preview meta tags from the doc.rust-lang.org website.
Linked Hostnames
1General Meta Tags
6- titlesize_of in std::mem - Rust
- charsetutf-8
- viewportwidth=device-width, initial-scale=1.0
- generatorrustdoc
- descriptionReturns the size of a type in bytes.
Link Tags
4- alternate icon../../static.files/favicon-32x32-6580c154.png
- icon../../static.files/favicon-044be391.svg
- stylesheet../../static.files/normalize-9960930a.css
- stylesheet../../static.files/rustdoc-84e720fa.css
Links
2- https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn+main()+%7B%0A++++%23%5Brepr(C)%5D%0A++++struct+FieldStruct+%7B%0A++++++++first:+u8,%0A++++++++second:+u16,%0A++++++++third:+u8%0A++++%7D%0A++++%0A++++//+The+size+of+the+first+field+is+1,+so+add+1+to+the+size.+Size+is+1.%0A++++//+The+alignment+of+the+second+field+is+2,+so+add+1+to+the+size+for+padding.+Size+is+2.%0A++++//+The+size+of+the+second+field+is+2,+so+add+2+to+the+size.+Size+is+4.%0A++++//+The+alignment+of+the+third+field+is+1,+so+add+0+to+the+size+for+padding.+Size+is+4.%0A++++//+The+size+of+the+third+field+is+1,+so+add+1+to+the+size.+Size+is+5.%0A++++//+Finally,+the+alignment+of+the+struct+is+2+(because+the+largest+alignment+amongst+its%0A++++//+fields+is+2),+so+add+1+to+the+size+for+padding.+Size+is+6.%0A++++assert_eq!(6,+size_of::%3CFieldStruct%3E());%0A++++%0A++++%23%5Brepr(C)%5D%0A++++struct+TupleStruct(u8,+u16,+u8);%0A++++%0A++++//+Tuple+structs+follow+the+same+rules.%0A++++assert_eq!(6,+size_of::%3CTupleStruct%3E());%0A++++%0A++++//+Note+that+reordering+the+fields+can+lower+the+size.+We+can+remove+both+padding+bytes%0A++++//+by+putting+%60third%60+before+%60second%60.%0A++++%23%5Brepr(C)%5D%0A++++struct+FieldStructOptimized+%7B%0A++++++++first:+u8,%0A++++++++third:+u8,%0A++++++++second:+u16%0A++++%7D%0A++++%0A++++assert_eq!(4,+size_of::%3CFieldStructOptimized%3E());%0A++++%0A++++//+Union+size+is+the+size+of+the+largest+field.%0A++++%23%5Brepr(C)%5D%0A++++union+ExampleUnion+%7B%0A++++++++smaller:+u8,%0A++++++++larger:+u16%0A++++%7D%0A++++%0A++++assert_eq!(2,+size_of::%3CExampleUnion%3E());%0A%7D&edition=2024
- https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn+main()+%7B%0A++++//+Some+primitives%0A++++assert_eq!(4,+size_of::%3Ci32%3E());%0A++++assert_eq!(8,+size_of::%3Cf64%3E());%0A++++assert_eq!(0,+size_of::%3C()%3E());%0A++++%0A++++//+Some+arrays%0A++++assert_eq!(8,+size_of::%3C%5Bi32;+2%5D%3E());%0A++++assert_eq!(12,+size_of::%3C%5Bi32;+3%5D%3E());%0A++++assert_eq!(0,+size_of::%3C%5Bi32;+0%5D%3E());%0A++++%0A++++%0A++++//+Pointer+size+equality%0A++++assert_eq!(size_of::%3C%26i32%3E(),+size_of::%3C*const+i32%3E());%0A++++assert_eq!(size_of::%3C%26i32%3E(),+size_of::%3CBox%3Ci32%3E%3E());%0A++++assert_eq!(size_of::%3C%26i32%3E(),+size_of::%3COption%3C%26i32%3E%3E());%0A++++assert_eq!(size_of::%3CBox%3Ci32%3E%3E(),+size_of::%3COption%3CBox%3Ci32%3E%3E%3E());%0A%7D&edition=2024