使用结构声明内联声明枚举
Declare an Enum inline with a struct declaration
我可以有如下结构:
struct Example {
state: State,
properties: HashMap<String, String>,
}
enum State {
a, b, c,
}
如果 Example 结构是 State 枚举的唯一用户,我认为在结构中声明它是有意义的:
struct Example {
state: enum { a, b, c },
properties: HashMap<String, String>,
}
是否有任何有效的语法?
没有。没有这样的语法。
您可以查看Rust grammar for struct
s, the type of a field must be a type expression。类型表达式无法创建新类型。
我可以有如下结构:
struct Example {
state: State,
properties: HashMap<String, String>,
}
enum State {
a, b, c,
}
如果 Example 结构是 State 枚举的唯一用户,我认为在结构中声明它是有意义的:
struct Example {
state: enum { a, b, c },
properties: HashMap<String, String>,
}
是否有任何有效的语法?
没有。没有这样的语法。
您可以查看Rust grammar for struct
s, the type of a field must be a type expression。类型表达式无法创建新类型。