BidSay HelloAnswerGet Paid Requirements File Type: .doc (Doc file) Formatting: College Rust This student has a history of requesting refunds at a higher rate than other users. (46%) To avoid disputes, make sure your help satisfies their requirements. Rust programming: Data Layout

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

  1. Write one program examlayout1.rs that, 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]>
    • 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.

  2. 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.

  3. Write one program examlayout2.rs that, 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>
Powered by WordPress