🦀Cargo

Describe about Cargo

Cargo is the package manager of Rust programming like mavenor npm.

Command:

  1. cargo init = Create Cargo.toml like a package.json of Rust

  2. cargo new <project_name> = Create the boilerplate of project including Cargo.toml and src folder that contain main.rs

  3. cargo build = Compile the project and create executable file in target/debug/executeable but for release you can use command cargo build --release it will create in target/release/executeable

  4. cargo run = It will compile and run the executable file.

  5. cargo update = It will update the dependencies and ignore Cargo.lock file.

  6. cargo check = It is to check for project can compile or not , use this command instead build to prevent step to create executable file and to ensure the code can compile.

File Structure

// Project structure after run cargo new abc
├── Cargo.lock
├── Cargo.toml
├── src
│   └── main.rs

Cargo.toml -> It will store the detail of the project like package.json

Cargo.lock-> It will store detail of dependencies that use in this project and version of it. In case that you clone this project in the future and your old dependencies is too old but new version will break the code when you use cargo to build it will always use the version of Cargo.lock instead to prevent this problem and you can update it manually for new version.

src/main.rs -> Main class of Rust to run the application

Last updated