I have a list of possible subcategory values, plus a list of subcategory grouping values that need to be associated. The user will enter a sub category value (Does this have to be an integer?) I need to check that this value is in the enum, but don't know what should be done if it isn't.
- Is there an "automatic" way of doing this check? Do we have to do this programmatically implementing the test on the enum?
- If the subcategory is used in a grouping category, how can it be used? How can it be set, how can it be read?
I'm thinking that the enums relationship would be something like this:
#[derive(Debug)]
pub enum Subtypes {
acost,
bcost,
//... other subtypes
}
#[derive(Debug)]
pub enum Grouping {
Exp(Subtypes),
//...other grouping associated with different subtypes
}
How do I define a new variable based on the grouping enum, and how can it be accessed?
// this doesn't work!!
let group = Grouping::Exp;
I think I'm missing something really fundamental. I don't know if enums are the way to go.