Site icon Tutor Bin

Rust programming: Data Layout

Rust programming: Data Layout

Description

WRITING CODE

When you are asked to write a program in the questions below, you should write one Rust source code file that lives in the code/plain/src/bin/ directory, has a mainfunction, and can be run with cargo run --bin foo (where foo.rs is the name of the Rust source code file). Do not use any additional crates in your solutions.

QUESTION: DATA LAYOUT

Write one program examlayout1.rsthat, for each of the following types, creates a value of that type and then prints it:

Vec<String>

&[u8]

Box<u8>

Box<&u8>

Box<[u8]>

  1. Box<&[u8]>

Box<Box<u8>>

Box<[u8; 4]>

  • [Box<u8>; 4]

[Option<u8>; 4]

  • Vec<[u8; 4]>

Use Debug formating with {:?}) to print each value. Your program must have a main function.

  • For each of the following types, draw a diagram to illustrate the data layout in memory when a local variable x contains a value of that type.

&[u8]

  • Box<u8>

Box<&u8>

  • Vec<[u8; 4]>

You can draw your answers on paper, take photos, and include them in your PDF. 

  • Write one program examlayout2.rsthat, for each of the following types, creates a value of that type and then prints out all of the memory addresses used to store the value. In particular, your program should print out the memory addresses used on the stack and on the heap. You must print out the memory addresses, and you can print out the contents of those memory addresses if you like. 

Box<u8>

  • Vec<String>

Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."

Exit mobile version