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 +``` +