From 1acb5ee469ced532468bb2fcefa48c9bc93550bd Mon Sep 17 00:00:00 2001 From: Manuel Thalmann <m@nuth.ch> Date: Fri, 28 Mar 2025 21:50:04 +0100 Subject: [PATCH] Add an `add_two` package --- add/Cargo.lock | 5 +++++ add/Cargo.toml | 1 + add/add_two/Cargo.toml | 6 ++++++ add/add_two/src/lib.rs | 3 +++ add/adder/Cargo.toml | 1 + add/adder/src/main.rs | 2 ++ 6 files changed, 18 insertions(+) create mode 100644 add/add_two/Cargo.toml create mode 100644 add/add_two/src/lib.rs diff --git a/add/Cargo.lock b/add/Cargo.lock index ce440ac..411403e 100644 --- a/add/Cargo.lock +++ b/add/Cargo.lock @@ -9,11 +9,16 @@ dependencies = [ "rand", ] +[[package]] +name = "add_two" +version = "0.1.0" + [[package]] name = "adder" version = "0.1.0" dependencies = [ "add_one", + "add_two", "rand", ] diff --git a/add/Cargo.toml b/add/Cargo.toml index 1448801..82deae7 100644 --- a/add/Cargo.toml +++ b/add/Cargo.toml @@ -3,4 +3,5 @@ members = [ "adder", "add_one", + "add_two", ] diff --git a/add/add_two/Cargo.toml b/add/add_two/Cargo.toml new file mode 100644 index 0000000..361894f --- /dev/null +++ b/add/add_two/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "add_two" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/add/add_two/src/lib.rs b/add/add_two/src/lib.rs new file mode 100644 index 0000000..559ac55 --- /dev/null +++ b/add/add_two/src/lib.rs @@ -0,0 +1,3 @@ +pub fn add_two(x: i32) -> i32 { + x + 2 +} diff --git a/add/adder/Cargo.toml b/add/adder/Cargo.toml index 6d2ec5e..76f9c5e 100644 --- a/add/adder/Cargo.toml +++ b/add/adder/Cargo.toml @@ -5,4 +5,5 @@ edition = "2024" [dependencies] add_one = { path = "../add_one" } +add_two = { path = "../add_two" } rand = "0.8.5" diff --git a/add/adder/src/main.rs b/add/adder/src/main.rs index 4e9cb78..30d187a 100644 --- a/add/adder/src/main.rs +++ b/add/adder/src/main.rs @@ -1,7 +1,9 @@ use add_one; +use add_two; use rand; fn main() { let num = 10; println!("Hello, world! {num} plus one is {}!", add_one::add_one(num)); + println!("{num} plus two is {}", add_two::add_two(num)); }