Package
workspace: A workspace is a set of packages that share the same Cargo.lock and output directory (usually target/).
Package, Crate, Module
- Packages, a Cargo feature that lets you build, test and share crates.
- ==0 or 1 library crates==, 0 or many binary crates.
- Crates, a tree of modules that produces a library or executable.
- Modules and use, let you control the organization, scope and privacy of paths.
- Paths, a way of naming an item, such as a struct, function, or module.
// Trick: _Nested paths_ and the _glob operator_ `*`.
use std::io::{self, Write};
use std::collections::*;
// Trick: Seperate mods into different files and dirs.
// src/lib.rs
mod front_of_house;
// src/front_of_house.rs
pub mod hosting;
// src/front_of_house/hosting.rs
pub fn add_to_waitlist() {}
Example
- main.rs
- my_lib/mod.rs
- my_lib/data.rs
my_lib/data.rs
pub struct Data {}
my_lib/mod.rs
pub mod data;
main.rs
mod my_lib;
fn test() {
my_lib::data::Data::new();
}
// or
mod my_lib;
use my_lib::data::Data;
fn test() {
Data::new();
}
Questions
A workspace is a set of packages that share the same Cargo.lock and output directory.
https://github.com/nikomatsakis/lalrpop
lib-foo/
Cargo.toml
src/
lib-bar/
Cargo.toml
src/
lib-main/
Cargo.toml
src/
https://github.com/google/xi-editor/tree/master/rust
Cargo.toml
src/
crates/
bar/
Cargo.toml
src/
foo/
Cargo.toml
src/