Open zargad opened 6 months ago
I just realized that this will create a new problem if there is a variant with the name Table
.
An implementation that solves this would be to make the enum accessible from the table, and not the other way around:
#[derive(EnumTable)]
enum Furniture {
Chair,
Lamp,
Table,
}
struct Shop<I: EnumTableTrait> {
prices: I,
best_item: I::Enum,
}
impl<I: EnumTableTrait> Shop<I> {
fn get_best_item_price(&self) -> u32 {
self.prices[self.best_item]
}
}
let furniture_shop = Shop<FurnitureTable> {
prices: FurnitureTable::new(32, 16, 9),
best_item: Furniture::Table,
};
assert_eq!(fruit_shop.get_best_item_price(), 9);
I would like to access the *Table type generated by EnumTable through the enum itself.
My main reason is that it would be possible to use them with their respective enum as generics. (example below) In addition, it would reduce the problem of name mangling in situations where the type *Table already exists (I don't know how much of a problem it is, or if that would make the name mangling redundant).
Here is an example of code that would be possible with that feature: