Puzzle 14 | Structure Sizing |
| use std::mem::size_of; |
| |
| struct VeryImportantMessage { |
| _message_type: u8, |
| _destination: u16 |
| } |
| |
| fn main() { |
| println!( |
| "VeryImportantMessage occupies {} bytes.", |
| size_of::<VeryImportantMessage>() |
| ); |
| } |
Guess the Output | |
---|---|
Try to guess what the output is before moving to the next page. |
The program will display the following output:
| VeryImportantMessage occupies 4 bytes. |
Discussion
_message_type and _destination are sized as you would expect, occupying 1 and 2 bytes ...
Get Rust Brain Teasers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.