Contents

Homework 2

 Back to syllabus

Toolchain

We will be testing this homework using Rust 1.66.1. The 1.66.1 version is only a security update from Rust 1.66.0, so your code will still be compatible with the autograder’s compiler if you use 1.66.0.

Get started

Starter code

In this homework, we will continue to tinker with ownership, borrowing, and lifetime, as well as exercise on error handling, traits, and iterators. We also have two bonus exercises on concurrency and unsafe.

To get started, clone the starter code:

1
2
git clone https://osdi.dev/rust-jhu/hw2-starter.git hw2
cd hw2/

Now, open src/lib.rs file in your favorite code editor. Find all the todo!()s and replace with your implementation code as required by the comments.

Exercises

The requirement in the comments are written in markdown, and can be compiled into HTML (see more). Run the following command to compile the docs.

1
cargo rustdoc --open -- --document-private-items

The --open option tells cargo to open the HTML document in a browser, and you will see a local webpage opened in your browser.

The --document-private-items option also generates documentation for private items.

Running

The repository is structured as a library-only project. It does not compile into any standalone executable files. To test the correctness of your code, run cargo test --release in the command line. You will see test framework output showing what cases have passed and failed, and also output the reason for the failed check.

Requirement: In this homework, you should not:

  • use any unsafe code (except Exercise 6)
  • add #![...] options to the beginning of the file or module
  • change any definition

You can modify the test cases, and also add your own test cases.

Note: the official test cases on Gradescope will be different from the sample test cases in the starter code. Therefore, you may want to add your own test cases to test more exhaustively.

Submission

This homework is due on January 22nd, 2023 at 23:59pm.

Submit only the lib.rs file to Gradescope.