Before you continue: If you havenβt already, you should have Rust installed. Make some Google search π€·π½ββοΈ.
Create a directory to keep our project. Since weβre learning Rust, I propose we create a workspace1 so we can put all learning projects in there.
Note that we donβt need to use workspaces. This is just anticipating future exercises you do β so you donβt clutter your file system with lots of folders. Letβs go.
# you can name the directory anything you want. eg. rustws
mkdir learn-rust
cd learn-rust
Next is to add a manifest file to the folder: Cargo.toml
[workspace]
members = [
"quiz"
]
resolver = "2"
Letβs add the quiz
package to the workspace.
cargo new quiz --bin
If you didnβt add quiz
to workspace.members
before running this command, you get a helpful message suggesting you do so. Thatβs one beauty of Rust. Error messages are very useful and mostly give hints on how to resolve them.
Run
To run our quiz
binary, do:
cargo run -p quiz
From now onwards, when I say letβs run the app, this is the command to run.
The folder structure should look like this:
.
βββ Cargo.lock
βββ Cargo.toml
βββ quiz
βββ Cargo.toml
βββ src
βββ main.rs