为枚举导出std :: hash :: Hash

时间:2017-08-24 17:28:33

标签: enums rust

我在为枚举自动导出Hash特征时遇到问题。我的代码将Hash指定为我的枚举的特征,但编译器告诉我我没有实现它。

以下是代码:

use std::collections::HashSet;
use std::hash::Hash;

#[derive(Hash, Eq, PartialEq, Debug, Clone)]
enum DishCategory {
    Green,
    Carb,
    Protein,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
struct Dish {
    name: String,
    ingredients: Vec<String>,
    dish_type: HashSet<DishCategory>,
}

编译器给出的错误:

error[E0277]: the trait bound `std::collections::HashSet<DishCategory>: std::hash::Hash` is not satisfied
  --> src/main.rs:15:5
   |
15 |     dish_type: HashSet<DishCategory>,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::hash::Hash` is not implemented for `std::collections::HashSet<DishCategory>`
   |
   = note: required by `std::hash::Hash::hash`

我正在使用Rust 1.19.0(0ade33941 2017-07-17

我做错了什么?

0 个答案:

没有答案