From 680c8633e6206085ad417c6055e17f6d30f462a4 Mon Sep 17 00:00:00 2001 From: Jordan Gong Date: Wed, 9 Sep 2020 21:52:02 +0800 Subject: Manage multiple packages using workspaces --- add/.gitignore | 18 ++++++++++++++++++ add/Cargo.toml | 7 +++++++ add/add-one/.gitignore | 18 ++++++++++++++++++ add/add-one/Cargo.toml | 10 ++++++++++ add/add-one/src/lib.rs | 13 +++++++++++++ add/adder/.gitignore | 18 ++++++++++++++++++ add/adder/Cargo.toml | 10 ++++++++++ add/adder/src/main.rs | 10 ++++++++++ 8 files changed, 104 insertions(+) create mode 100644 add/.gitignore create mode 100644 add/Cargo.toml create mode 100644 add/add-one/.gitignore create mode 100644 add/add-one/Cargo.toml create mode 100644 add/add-one/src/lib.rs create mode 100644 add/adder/.gitignore create mode 100644 add/adder/Cargo.toml create mode 100644 add/adder/src/main.rs (limited to 'add') diff --git a/add/.gitignore b/add/.gitignore new file mode 100644 index 0000000..e629269 --- /dev/null +++ b/add/.gitignore @@ -0,0 +1,18 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/rust +# Edit at https://www.toptal.com/developers/gitignore?templates=rust + +### Rust ### +# Generated by Cargo +# will have compiled files and executables +/target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# End of https://www.toptal.com/developers/gitignore/api/rust + diff --git a/add/Cargo.toml b/add/Cargo.toml new file mode 100644 index 0000000..37b9688 --- /dev/null +++ b/add/Cargo.toml @@ -0,0 +1,7 @@ +[workspace] + +members = [ + "adder", + "add-one", +] + diff --git a/add/add-one/.gitignore b/add/add-one/.gitignore new file mode 100644 index 0000000..e629269 --- /dev/null +++ b/add/add-one/.gitignore @@ -0,0 +1,18 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/rust +# Edit at https://www.toptal.com/developers/gitignore?templates=rust + +### Rust ### +# Generated by Cargo +# will have compiled files and executables +/target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# End of https://www.toptal.com/developers/gitignore/api/rust + diff --git a/add/add-one/Cargo.toml b/add/add-one/Cargo.toml new file mode 100644 index 0000000..9d35934 --- /dev/null +++ b/add/add-one/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "add-one" +version = "0.1.0" +authors = ["Jordan Gong "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +rand = "0.5.5" diff --git a/add/add-one/src/lib.rs b/add/add-one/src/lib.rs new file mode 100644 index 0000000..40ceb12 --- /dev/null +++ b/add/add-one/src/lib.rs @@ -0,0 +1,13 @@ +pub fn add_one(x: i32) -> i32 { + x + 1 +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + assert_eq!(3, add_one(2)); + } +} diff --git a/add/adder/.gitignore b/add/adder/.gitignore new file mode 100644 index 0000000..e629269 --- /dev/null +++ b/add/adder/.gitignore @@ -0,0 +1,18 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/rust +# Edit at https://www.toptal.com/developers/gitignore?templates=rust + +### Rust ### +# Generated by Cargo +# will have compiled files and executables +/target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# End of https://www.toptal.com/developers/gitignore/api/rust + diff --git a/add/adder/Cargo.toml b/add/adder/Cargo.toml new file mode 100644 index 0000000..91118cb --- /dev/null +++ b/add/adder/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "adder" +version = "0.1.0" +authors = ["Jordan Gong "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +add-one = { path = "../add-one" } diff --git a/add/adder/src/main.rs b/add/adder/src/main.rs new file mode 100644 index 0000000..7deb796 --- /dev/null +++ b/add/adder/src/main.rs @@ -0,0 +1,10 @@ +use add_one; + +fn main() { + let num = 10; + println!( + "Hello, world! {} plus one is {}!", + num, + add_one::add_one(num) + ); +} -- cgit v1.2.3