Skip to content

Commit

Permalink
Update archives.
Browse files Browse the repository at this point in the history
  • Loading branch information
poneding committed Jun 17, 2024
1 parent 3006980 commit 5284073
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions content/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@

## Rust 编程

- [Cargo 管理工具](rust/cargo.md)
- [Rust 入门](rust/getting-started.md)
- [Rust 入门](rust/01-getting-started.md)
- [Cargo 管理工具](rust/02-cargo.md)
- [查看根目录](rust/rust-programming.md)
- [Rust VSCode 调试](rust/vscode-debugging.md)
- [Rust WASM 编程](rust/wasm-programming.md)
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,4 @@ rustup self uninstall
```

---
[« Cargo 管理工具](cargo.md)

[» 查看根目录](rust-programming.md)
[» Cargo 管理工具](02-cargo.md)
17 changes: 16 additions & 1 deletion content/rust/cargo.md → content/rust/02-cargo.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ cargo publish --allow-dirty
- git:rust 版本的 git 仓库,适用于未发布或者开发阶段;
- local crate:本地 rust 库,可用于调试。

## 版本格式

依赖的版本范围规则参考如下,基于这样的规则,rust 会使用版本范围内最大版本号作为依赖的最终版本,例如如果定义版本为 `some_crate = "1.2.3"` 但是 `some_crate` 当前最高版本为 `1.8.9`,那么 Cargo 会自动使用 ·1.8.9· 版本作为依赖。

```toml
Expand Down Expand Up @@ -152,6 +154,14 @@ some_crate = "1.2.*" => 版本范围[1.2.0, 1.3.0)
some_crate = ">=1.2, < 1.5" => 版本范围[1.2.0, 1.5.0)
```

使用别名引入两个版本不同的库:

```toml
[dependencies]
some_crate_v1 = { version = "1.0.0", package = "rand" }
some_crate_v2 = { version = "2.0.0", package = "rand" }
```

## 添加依赖

```bash
Expand All @@ -162,6 +172,9 @@ cargo add hello-world
# 添加依赖并使用 features
cargo add serde --features derive,serde_derive

# 添加 git 仓库依赖,Cargo.toml 依赖信息中会包含 git 地址
cargo add myrlib --git https://github.com/poneding/myrlib.git

# 添加本地依赖
cargo add hello-world --path ../hello-world
```
Expand Down Expand Up @@ -264,4 +277,6 @@ cargo build -p hello_world
```

---
[» Rust 入门](getting-started.md)
[« Rust 入门](01-getting-started.md)

[» 查看根目录](rust-programming.md)
4 changes: 2 additions & 2 deletions content/rust/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

# Rust 编程

[Cargo 管理工具](cargo.md)
[Rust 入门](01-getting-started.md)

[Rust 入门](getting-started.md)
[Cargo 管理工具](02-cargo.md)

[查看根目录](rust-programming.md)

Expand Down
2 changes: 1 addition & 1 deletion content/rust/rust-programming.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ let s2 = s1.as_ref();
设置 `RUST_BACKTRACE=1` 环境变量值,可以追踪到 panic 位置,例如:

---
[« Rust 入门](getting-started.md)
[« Cargo 管理工具](02-cargo.md)

[» Rust VSCode 调试](vscode-debugging.md)

0 comments on commit 5284073

Please sign in to comment.