111763 Views
85221 Views
83639 Views
51774 Views
49949 Views
48472 Views
Obsidian - the best tool for Makers
10 Projects for your Raspberry Pi Pico
Raspberry Pi Telegraf Setup with Docker
Setting Up Dynamic DNS on a Raspberry Pi for Self-Hosting
Raspberry Pi WordPress Setup with Docker
Raspberry Pi WireGuard VPN Setup with Docker
Using the Raspberry Pi Pico's Built-in Temperature Sensor
Getting Started with SQL
Introduction to the Linux Command Line on Raspberry Pi OS
How to install MicroPython
Wall Drawing Robot Tutorial
BrachioGraph Tutorial
KevsRobots Learning Platform
100% Percent Complete
By Kevin McAleer, 2 Minutes
Cargo is not just a package manager; it’s also a Rust project’s build system. It manages building your code, downloading the libraries your code depends on, and building those libraries. This bonus lesson will guide you through creating a new Rust project with Cargo, managing dependencies, and building projects.
To start a new Rust project with Cargo, you can use the following command:
cargo new project_name
This command creates a new directory called project_name containing a Cargo.toml file (the manifest file for Rust projects) and a src directory with a main.rs file. The Cargo.toml file will include basic metadata about your project and a list of dependencies.
project_name
Cargo.toml
src
main.rs
Add dependencies to your project by listing them under [dependencies] in your Cargo.toml file. For example, to add the serde library:
[dependencies]
serde
[dependencies] serde = "1.0"
When you build your project, Cargo will automatically download and compile your dependencies and all of their dependencies.
To build your project, run the following command in your project directory:
cargo build
This command compiles your project and all of its dependencies. If the build is successful, Cargo places the executable in target/debug/project_name.
target/debug/project_name
To build and run your project in one step, you can use:
cargo run
If your project compiles successfully, Cargo will then run the resulting executable.
In this bonus lesson, you learned how to create a new Rust project using Cargo, manage your project’s dependencies, and build and run your project. Cargo is a powerful tool that simplifies many aspects of Rust development, making it easier to manage large projects and their dependencies.
< Previous