From 33a2ae3d1690c7621637089c152958c2a2e5af56 Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Sat, 25 May 2024 17:46:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E7=A9=BA=E9=97=B4=20workspac?= =?UTF-8?q?e=20=E8=AF=95=E6=B0=B4=20=E6=9B=B4=E6=96=B0=20README.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 +++++ 5.function/Cargo.toml | 7 +++++++ 5.function/src/main.rs | 3 +++ Cargo.toml | 24 ++++++++++++++++++++++ README.MD | 45 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 84 insertions(+) create mode 100644 5.function/Cargo.toml create mode 100644 5.function/src/main.rs create mode 100644 Cargo.toml create mode 100644 README.MD diff --git a/.gitignore b/.gitignore index 429b2fc..95bf776 100644 --- a/.gitignore +++ b/.gitignore @@ -92,3 +92,8 @@ fabric.properties .idea/caches/build_file_checksums.ser !/.idea/git_toolbox_prj.xml + + +# Added by cargo + +/target diff --git a/5.function/Cargo.toml b/5.function/Cargo.toml new file mode 100644 index 0000000..eca2fe4 --- /dev/null +++ b/5.function/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "function" +# 继承 workspace 的版本号 +version.workspace = true +edition = "2021" + +[dependencies] diff --git a/5.function/src/main.rs b/5.function/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/5.function/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..f7e3df1 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,24 @@ +# 没有 [package] 为虚拟清单类型的 工作空间 + +[workspace.package] +# 为工作空间下的子包 定义版本号 +# 子包 可以 通过 version.workspace 继承 工作空间的版本号 +version = "0.1.0" + +[workspace] +resolver = "2" +exclude = [ + ".git", + ".idea", + ".vscode", + "1.hello_world" +] +members = [ + "2.hello_cargo", + "3.guessing_game", + "4.variables", + "5.function", + + "x.bubble_sort" +] + diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..95f4ee8 --- /dev/null +++ b/README.MD @@ -0,0 +1,45 @@ +# Rust Study +## 自学 Rust 仓库 + +### 参考资料 +- [Rust 语言中文社区](https://rustcc.cn/) +- [Rust 官方文档](https://doc.rust-lang.org/book/) +- [Rustlings](https://github.com/rust-lang/rustlings) +- [Rust by Example](https://doc.rust-lang.org/rust-by-example/) +- [Rustlings](https://github.com/rust-lang/rustlings) +- [Rust 程序设计语言](https://kaisery.github.io/trpl-zh-cn/) + + +## 子包创建 +例子: +```shell +cargo new 5.function --name function +``` +### 编译某个子包 +```shell +cargo build --manifest-path 5.function/Cargo.toml +``` +### 运行某个子包 +```shell +cargo run --manifest-path 5.function/Cargo.toml +``` + +### 工作空间 workspace +参考文档 +- https://course.rs/cargo/reference/workspaces.html + +#### 编译所有子包 +```shell +cargo build --workspace +``` + +#### 编译工作空间下 某个子包 +```shell +cargo build -p variables +``` + +#### 运行工作空间下 某个子包 +```shell +cargo run -p function +``` +