In this step, we will initialize a basic rust project, where we can start building our simple Rust state machine.
Create a directory where you want your project to live, and navigate to that folder. We will be using a folder named rust-state-machine
.
mkdir rust-state-machinecd rust-state-machine
In that folder, initialize your rust project using cargo init
:
cargo init
This will scaffold a basic Rust executable which we can use to start building.
You can verify that your new project is working as expected by running:
cargo run
You should see "Hello, World!" appear at the end of the compilation:
➜ rust-state-machine git:(master) ✗ cargo runCompiling rust-state-machine v0.1.0 (/Users/shawntabrizi/Documents/GitHub/rust-state-machine)Finished dev [unoptimized + debuginfo] target(s) in 2.19sRunning `target/debug/rust-state-machine`Hello, world!
If we look at what has been generated, in that folder, you will see the following:
src
folder.package.json
that you would see in a Node.JS project. We will modify this in the future when we import crates to use in our project, but We can leave this alone for now.cargo.toml
and the compilation. This usually defines the very specific versions of each crate being imported, and should not be manually edited.target/*
- You might also see a target folder if you did cargo run
. This is a folder where all the build artifacts are placed during compilation. We do not commit this folder into our git history.All of this should be pretty familiar to you if you have already had some minimal experience with Rust. If any of this is new, I would suggest you first walk through the Rust Book and Rust by Example, as this is already an indication that this guide might not be targeted at your level of knowledge.