I could have a structure like the following:
struct Example {
state: State,
properties: HashMap<String, String>,
}
enum State {
a, b, c,
}
If the Example structure is the only user of the State enum, I think it would make sense to declare it in the struct:
struct Example {
state: enum { a, b, c },
properties: HashMap<String, String>,
}
Is there any valid syntax for this?
No. There is no such syntax.
You can check the Rust grammar for structs, the type of a field must be a type expression. Type expressions cannot create new types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With