module-concept

Rust Crate-wide visibility

Use crate-wide visibility for helpers shared among internal components without exposing them as a library API to downstream crates. The crate boundary is not the package or workspace boundary. Expected result (not executed): 105 Why: Both modules belong to the same crate. Common mistake: Assuming a second binary in the same package can access pub(crate) library items.

Formal Syntax & Structure

rust syntaxrust
pub(crate) fn helper() {}

Working Example

Example Snippetrust
mod tax { pub(crate) fn rate() -> u32 { 5 } }mod invoice { pub fn total() -> u32 { 100 + crate::tax::rate() } }fn main() { println!("{}", invoice::total()); }
Rust Reference