RS.CLIPPY.PARTIAL_PUB_FIELDS
Partial fields of a struct are public
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: partial_pub_fields. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks whether some but not all fields of a struct are public.
Either make all fields of a type public, or make none of them public
Why restrict this?
Most types should either be:
- Abstract data types: complex objects with opaque implementation which guard interior invariants and expose intentionally limited API to the outside world.
- Data: relatively simple objects which group a bunch of related attributes together, but have no invariants.
Example
pub struct Color {
pub r: u8,
pub g: u8,
b: u8,
}
Use instead:
pub struct Color {
pub r: u8,
pub g: u8,
pub b: u8,
}