Skip to content

Latest commit

Β 

History

History
59 lines (39 loc) Β· 2.47 KB

File metadata and controls

59 lines (39 loc) Β· 2.47 KB

πŸ“¦ Cargo

πŸ‘€ Fast Lookup

  • Cargo is Rust's package manager and build system.
  • Use cargo check to quickly check for errors without building an executable.
  • Use cargo build to compile the project in debug mode, or cargo build --release for an optimized release build.

❓ What is Cargo?

Cargo is Rust's package manager and build system. It simplifies the process of managing Rust projects, including dependencies, building, testing, and packaging.

πŸš€ Featured Commands

  • 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 build because it skips the linking step.
    • Use cargo check mainly and use cargo build only when you need the executable.
  • 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/debug directory.
    • Use cargo build --release for a release build, which is optimized for performance. Executables will be placed in the target/release directory.
  • 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.

πŸ“„ Cargo Related Files and Keywords

πŸ“ Cargo.toml

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".

πŸ”’ Cargo.lock

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. (build command)
  • Should not be manually edited.