okgr

Introduction to Rust πŸ¦€ with egui

Create project ft. cargo workspaces

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

Footnotes

  1. Read about cargo workspaces here ↩