visibility
Who is allowed to use an item: only its own module, the whole crate, or anyone.
Items are private to their module by default; pub makes them visible wherever their parent is, pub(crate) within the crate, pub(super) in the parent module, and pub(in path) in a named ancestor.
Loading interactive…
Examples
If
pub struct Setpoint { celsius: f32 }keepscelsiusprivate, code outside its module can callSetpoint::new(21.0)but writingSetpoint { celsius: 21.0 }fails with E0451.
See also