minigrep
codePlease read this description in its entirety before starting the lab!
This lab will be a hands-on experience in 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.
This lab requires the use of some more advanced Rust concepts, which you will read about beforehand. Take your time, and try to make sure you understand everything – you still have until Tuesday to submit.
In this lab, you will:
cargo
and the Rust
toolchain to manage a projectIf you have not set up Rust, 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).
Read the following chapters in the Rust book:
These chapters are more advanced Rust concepts than those we discussed in lecture. If you need a refresher, use Chapters 3-6 in the Rust book as a reference.
As you do your reading, try out each code snippet in your own local copy of Rust. 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.
Go through Chapter 12, “Building
a Command Line Program” in the Rust book. Follow each step,
line-by-line, all the way until you have a complete
minigrep
program. Once again, I encourage you make sure
to type each line into your editor.
After you’ve completed the project, add comments
to the top of src/main.rs
answering the following
questions:
minigrep
. How are these syntax structures similar to
programming languages you have seen in the past? How are they
different?minigrep
functionality. How did you overcome
them?minigrep
. How did you test your code? Why
was it helpful?Upload the following to Blackboard before the due date above:
gzip
ped code archive of
your minigrep
project directory
gzip
the directory, make sure to run
cargo clean
target/
src/
as well
asCargo.toml
.src/main.rs
should contain comments
responding to the questions above. These may take up several
lines.