Puzzle 14Structure 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

images/aside-icons/important.png

Try to guess what the output is before moving to the next page.

images/hline.png

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 live online training, plus books, videos, and digital content from nearly 200 publishers.