- Cargo is Rust's package manager and build system.
- Use
cargo checkto quickly check for errors without building an executable. - Use
cargo buildto compile the project in debug mode, orcargo build --releasefor an optimized release build.
Cargo is Rust's package manager and build system. It simplifies the process of managing Rust projects, including dependencies, building, testing, and packaging.
-
cargo --version: Displays the version of Cargo installed. -
cargo new <project_name>: Creates a new Rust project with the specified name. -
cargo check: Checks the current project for errors without producing an executable.- This is faster than
cargo buildbecause it skips the linking step. - Use
cargo checkmainly and usecargo buildonly when you need the executable.
- This is faster than
-
cargo build: Compiles the current project.- By default, it builds in debug mode, which is optimized for fast compilation. It creates an executable in the
target/debugdirectory. - Use
cargo build --releasefor a release build, which is optimized for performance. Executables will be placed in thetarget/releasedirectory.
- By default, it builds in debug mode, which is optimized for fast compilation. It creates an executable in the
-
cargo run: Runs the current project. -
cargo test: Runs the tests for the current project. -
cargo doc --open: Generates documentation for the current project and opens it in a web browser.
The manifest file for Rust projects, containing metadata and dependencies.
[package]: Section header for package metadata.name: The name of the package.version: The version of the package.authors: The authors of the package.edition: The edition of Rust used by the package.
[dependencies]: Section for specifying dependencies. In Rust, packages are called "crates".
The lock file that records the exact versions of dependencies used in the project. It ensures reproducible builds by locking down the versions of all dependencies.
- Automatically generated by Cargo when dependencies are added or updated. (
buildcommand) - Should not be manually edited.