rust - 使用 struct 声明内联声明 Enum
问题描述
我可以有如下结构:
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>,
}
有什么有效的语法吗?
解决方案
不,没有这样的语法。
您可以检查s的Rust 语法struct
,字段的类型必须是类型表达式。类型表达式不能创建新类型。
推荐阅读
- c++ - 以下哪个更有效?
- jquery - jquery滚动到元素问题
- sql - 避免在 Spark SQL 中对 GROUP BY 进行随机播放
- c++ - C++ 抽象类是否需要遵守五法则?
- python - Python将小时-分钟更改为小时结束格式
- php - 类型错误:传递给 Illuminate\Auth\SessionGuard::login() 的参数 1 必须实现接口 Illuminate\Contracts\Auth\Authenticatable
- apache-kafka-streams - 如何为 Transformer 设置 State Store
- ansible - 条件失败时的 Ansible 倍数
- ruby - 如何限制 Sinatra/Active Record 中数据库字符串值的字符/字数?
- vba - VBA 访问消息框问题