Homework 1
Toolchain
If you haven’t setup the Rust toolchain, head to https://rustup.rs. The website detects your operating system and gives you instruction on how to install in your system. For example, on Linux and macOS, the following is the suggested installation method:
|
|
You can directly proceed with the default installation option when you see
prompts. By default, the Rust toolchain will be installed in .cargo/
and
.rustup/
folders in your home directory.
Alternatively, you can also use the package manager on your operating system. Just make sure to use a recent version to prevent potential breakage. We will be testing all the homework using Rust 1.66.0.
Get started
Starter code
In this homework, we will get familiar with the basic syntax, and exercise on mutability, ownership, borrowing, and lifetime. To get started, clone the starter code:
|
|
Now, open src/lib.rs
file in your favorite code editor. Find all the
unimplemented!()
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.
|
|
The --open
option tells cargo to open the HTML document in a browser, and you
will see a local webpage opened in your browser.
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
in the command line, or cargo test --doc
if only testing the
last exercise. You will see test framework output as below. It will show 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 - add
#![...]
options to the beginning of the file or module - change the function signatures unless otherwise required by specific exercises
You can modify the test cases, and also add your own test cases.
Note: the official test cases on Gradescope might 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.