dotcodeschool

dotcodeschool

Submit Feedback

Initialize your Rust Project

In this step, we will initialize a basic rust project, where we can start building our simple Rust state machine.

cargo init

  1. 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-machine
    cd rust-state-machine
  2. 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.

  3. 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 run
    Compiling rust-state-machine v0.1.0 (/Users/shawntabrizi/Documents/GitHub/rust-state-machine)
    Finished dev [unoptimized + debuginfo] target(s) in 2.19s
    Running `target/debug/rust-state-machine`
    Hello, world!

If we look at what has been generated, in that folder, you will see the following:

  • src/main.rs - This is the entry point to your program. We will be building everything for this project in the src folder.
  • Cargo.toml - This is a configuration file for your Rust project. Quite similar to a 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.lock - This is an autogenerated lock file based on your 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.

Loading...

Initialize your Rust Project

In this step, we will initialize a basic rust project, where we can start building our simple Rust state machine.

cargo init

  1. 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-machine
    cd rust-state-machine
  2. 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.

  3. 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 run
    Compiling rust-state-machine v0.1.0 (/Users/shawntabrizi/Documents/GitHub/rust-state-machine)
    Finished dev [unoptimized + debuginfo] target(s) in 2.19s
    Running `target/debug/rust-state-machine`
    Hello, world!

If we look at what has been generated, in that folder, you will see the following:

  • src/main.rs - This is the entry point to your program. We will be building everything for this project in the src folder.
  • Cargo.toml - This is a configuration file for your Rust project. Quite similar to a 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.lock - This is an autogenerated lock file based on your 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.

Loading...

Next