Rust 管理工具 Cargo

安装

1
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh

指令

1
2
3
4
5
6
7
8
9
10
11
cargo new demo # 创建一个 demo 项目

cargo new --vcs=git demo # 创建一个 demo 项目并且初始化 git

cargo run # 执行项目

cargo build # 构建项目

cargo build --release # 构建项目并且做优化

cargo check # 检查项目
1
2
3
├── Cargo.toml
└── src
└── main.rs

main.rs

1
2
3
fn main() {
println!("Hello, world!");
}

Cargo.toml

1
2
3
4
5
6
7
8
[package]
name = "hello_cargo"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

类似于 package.json