Workspaces
// # Think we run
mkdir greetings
touch greetings/Cargo.toml
cargo new greetings/lib
cargo new --bin greetings/examples/hello
// # That generates,
.
├── Cargo.toml
├── examples
│ └── hello
│ ├── Cargo.toml
│ └── src
│ └── main.rs
└── lib
├── Cargo.toml
└── src
└── lib.rs
// # Think we modify following files
// 01. greetings/Cargo.toml
[workspace]
members = [
"lib",
"examples/hello"
]
// 02.1 greetings/lib/Cargo.toml
[package]
name = "greetings"
version = "0.1.0"
authors = ["Dumindu Madunuwan"]
[dependencies]
// 02.2 greetings/lib/src/lib.rs
pub fn hello() {
println!("Hello, world!");
}
// 03.1 greetings/examples/hello/Cargo.toml
[package]
name = "hello"
version = "0.1.0"
authors = ["Dumindu Madunuwan"]
[dependencies]
greetings = { path = "../../lib" }
// 03.2 greetings/examples/hello/src/main.rs
extern crate greetings;
fn main() {
greetings::hello();
}Last updated