added workspaces example
This commit is contained in:
parent
eb0612b93b
commit
aec66ef7c8
6
the_book/workspaces/Cargo.toml
Normal file
6
the_book/workspaces/Cargo.toml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[workspace]
|
||||||
|
|
||||||
|
members = [
|
||||||
|
"adder",
|
||||||
|
"add_one",
|
||||||
|
]
|
9
the_book/workspaces/add_one/Cargo.toml
Normal file
9
the_book/workspaces/add_one/Cargo.toml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
[package]
|
||||||
|
name = "add_one"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
rand = "0.8.3"
|
12
the_book/workspaces/add_one/src/lib.rs
Normal file
12
the_book/workspaces/add_one/src/lib.rs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
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))
|
||||||
|
}
|
||||||
|
}
|
9
the_book/workspaces/adder/Cargo.toml
Normal file
9
the_book/workspaces/adder/Cargo.toml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
[package]
|
||||||
|
name = "adder"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
add_one = {path = "../add_one"}
|
6
the_book/workspaces/adder/src/main.rs
Normal file
6
the_book/workspaces/adder/src/main.rs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
use add_one;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let num = 10;
|
||||||
|
println!("Hello World! {} plus 1 is {}", num, add_one::add_one(num));
|
||||||
|
}
|
Loading…
Reference in a new issue