There are of course a lot of options to choose from. Clippy's lints tend to be opinions. It's beneficial to have opinions, but they can change depending on context as well as several unrelated factors.
One option to consider is restructuring so that you don't have any Fruit
intermediate type for holding things in a Basket
. Perhaps the basket can also hold vegetables, tubers, fungi, and nuts. Maybe it can hold inedible items like flowers, clothes, and tools.
Categorizing these might be useful for storing them in other kinds of bins: Refrigerator
could be a good place to store fruits, but not clothes. But neither Basket
nor Refrigerator
need an intermediate type for this categorization. The storage types themselves are metonymously categorical:
struct Basket {
apples: Vec<Apple>,
potatoes: Vec<Potato>,
clothes: Vec<Clothes>,
hammers: Vec<Hammer>,
// ...
}
struct Refrigerator {
apples: Vec<Apple>,
potatoes: Vec<Potato>,
// ...
}
enum Apple {
GoldenDelicious,
GrannySmith,
Macintosh,
// ...
}
enum Clothes {
Pants,
Shirt,
Sock,
// ...
}
enum Hammer {
BallPeen,
Claw,
Sledge,
// ...
}
enum Potato {
Russet,
Sweet,
YukonGold,
// ...
}
I decided to subdivide Apple
into varieties of apples, and chose to do the same with Hammer
.
They could just as well be simple unit structs: struct Apple;
and struct Hammer;
if they need no further classification, of course. And then the inner Vec
can be simplified to just a counter, since all Apple
s will be alike and all Hammer
s will be alike.
I think this is a good illustration that there are a lot of approaches to organizing your data model. And the best way really depends on the functional requirements of the project.
It should be noted that you may disagree with Clippy, and that's ok! You are encouraged to #[allow(clippy:...)]
or configure lints in your Cargo.toml
to suit your needs.
Hope this is helpful guidance. But it's just, like, my opinion, man.