Cargo is Rust's build system and package manager. It handles a lot of tasks for you, such as building your code, downloading the libraries your code depends on, and building those libraries.
To build and run a Cargo project, you can use the following commands:
- `cargo build` to build your project and create an executable file in the target directory.
- `cargo run` to compile the code and then run the resultant executable all in one command.
- `cargo check` to quickly check your code to make sure it compiles but doesn't produce an executable.
The `cargo run` command is the most convenient way to build and run a Cargo project. It will compile your code if it hasn't been compiled recently, and then run the executable. If you make changes to your code, you can run `cargo run` again to rebuild and run the updated code.
The `cargo check` command is a good way to quickly check your code to make sure it compiles. It's often much faster than `cargo build` because it doesn't produce an executable. If you're continually checking your work while writing the code, using `cargo check` will speed up the process of letting you know if your project is still compiling!
The `target/debug` directory is where Cargo stores the compiled binaries for your project. This directory is created when you run `cargo build` for the first time.