I see. I was trying to avoid having to write that boiler plate code in each of the concrete types of ProductType. If i have 10 concrete types of ProductType i will need to repeat in each of them
That's where macros shine, it's a little advanced however. I made a playground using a declarative macro because I haven't used procedural ones yet. With a procedural macro you could simply do:
#[derive(ProductType)]
struct Food {
// snip
}
There is an example in the book but it will probably make you jump several chapters, for now I think you should stick with copy/paste.
It seems like you're trying to mimic common supertype inheritance model, but it's painful as Rust enforces composition over inheritance idiom. Then why don't you solve it using composition?
error[E0277]: the trait bound `std::boxed::Box<(dyn Category + 'static)>: Category` is not satisfied
--> test.rs:27:9
|
27 | &self.category
| ^^^^^^^^^^^^^^ the trait `Category` is not implemented for `std::boxed::Box<(dyn Category + 'static)>`
|
= note: required for the cast to the object type `dyn Category`