RS.CLIPPY.STRUCT_FIELD_NAMES
Structs where all fields share a prefix/postfix or contain the name of the struct
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: struct_field_names. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Detects struct fields that are prefixed or suffixed by the same characters or the name of the struct itself.
Why is this bad?
Information common to all struct fields is better represented in the struct name.
Limitations
Characters with no casing will be considered when comparing prefixes/suffixes
This applies to numbers and non-ascii characters without casing
e.g. foo1 and foo2 is considered to have different prefixes
(the prefixes are foo1 and foo2 respectively), as also bar螃, bar蟹
Example
struct Cake {
cake_sugar: u8,
cake_flour: u8,
cake_eggs: u8
}
Use instead:
struct Cake {
sugar: u8,
flour: u8,
eggs: u8
}
Configuration
-
struct-field-name-threshold: The minimum number of struct fields for the lints about field names to trigger(default:
3)