# Cargo (opens new window)

  • cargo new hello_world --bin
  • cargo build 编译
  • cargo run 编译并运行
  • cargo update
  • cargo test

# toml字段值 (opens new window)

# 依赖项 (opens new window)

要依赖crates.io上托管的库,请将其添加到您的Cargo.toml.

[package]
name = "hello_world"
version = "0.1.0"
edition = "2021"

[dependencies]
time = "0.1.12"
regex = "0.1.41"
regex = { git = "https://github.com/rust-lang/regex", branch = "next" }
some-crate = { version = "1.0", registry = "my-registry" }
hello_utils = { path = "hello_utils" }
hello_utils = { path = "hello_utils", version = "0.1.0" }
1
2
3
4
5
6
7
8
9
10
11
12

# 项目目录

.
├── Cargo.lock
├── Cargo.toml
├── src/                         源代码
│   ├── lib.rs                   默认库文件
│   ├── main.rs                  默认的可执行文件
│   └── bin/                     其他可执行文件
│       ├── named-executable.rs
│       ├── another-executable.rs
│       └── multi-file-executable/
│           ├── main.rs
│           └── some_module.rs
├── benches/          
│   ├── large-input.rs
│   └── multi-file-bench/
│       ├── main.rs
│       └── bench_module.rs
├── examples/                     示例
│   ├── simple.rs
│   └── multi-file-example/
│       ├── main.rs
│       └── ex_module.rs
└── tests/                        集成测试
    ├── some-integration-tests.rs
    └── multi-file-test/
        ├── main.rs
        └── test_module.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28