Please read this description in its entirety before starting the lab!
This lab will be our first experience writing Rust, a programming language for secure systems engineering. To quote the Rust book:
The Rust programming language helps you write faster, more reliable software. High-level ergonomics and low-level control are often at odds in programming language design; Rust challenges that conflict. Through balancing powerful technical capacity and a great developer experience, Rust gives you the option to control low-level details (such as memory usage) without all the hassle traditionally associated with such control.
In this lab, you will:
cargo
and the Rust toolchain to manage a projectIf you did not set up Rust during lecture, you’ll need to install it first.
Open a terminal and enter the following command:
$ curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
The command downloads and runs the rustup
script, which installs Rust:
Rust is installed now. Great!
I highly recommend installing VSCode and its Rust extension while learning Rust. Take a minute to do so before you begin – part of Rust’s value is in its robust tooling and developer support. There also is support for other IDEs and text editors. For example, if you are a l33t h4x0r
and want to use Vim, you can still take advantage of the tooling.
Note. If you were unable to bring your laptop to class today, or cannot set up Rust right now, you can also complete this lab using the Rust Playground (though the experience might be degraded on a tablet or smartphone).
Go through Chapter 2, “Programming a Guessing Game” in the Rust book. Follow each step, line-by-line. By the end, you will have a working guessing game – and have written your first real Rust program!
I encourage you make sure to type each line into your editor, rather than copy-and-pasting. It may seem silly, but typing the code well help you get the muscle memory of writing Rust faster. I will be available if you want to ask any questions.
After you’ve completed the guessing game, add comments to the top of src/main.rs
answering the following three questions:
Upload the following to Blackboard before the due date above:
src/main.rs
with your guessing game code