use std::collections::HashMap;
#[derive(Debug)]
enum Y {
Y1,
Y2,
}
#[derive(Debug)]
struct X {
items : HashMap<Y, i8>,
}
HashMap
has bounds on its first parameter (look at the "Methods" section): K: Eq + Hash
. The slightly confusing error message is because the derive
d Debug
implementation for X
is trying to use the Debug
implementation for HashMap
, which has these bounds:
impl<K, V, S> Debug for HashMap<K, V, S> where K: Eq + Hash + Debug, V: Debug, S: HashState
But Y
doesn't satisfy the bounds, so HashMap<Y, i8>
doesn't implement Debug
.
That is, your enum needs to implement those two traits, which can be done with derive
:
use std::collections::HashMap;
#[derive(Debug, PartialEq, Eq, Hash)]
enum Y {
Y1,
Y2,
}
#[derive(Debug)]
struct X {
items : HashMap<Y, i8>,
}
fn main()
{
println!("Hello, world!")
}
Closing, but thanks for filing nonetheless!
Can we maybe include this as a question & answer on Stack Overflow. It'll be helpful for beginners who learn through Googling their problems.
Most helpful comment
HashMap
has bounds on its first parameter (look at the "Methods" section):K: Eq + Hash
. The slightly confusing error message is because thederive
dDebug
implementation forX
is trying to use theDebug
implementation forHashMap
, which has these bounds:But
Y
doesn't satisfy the bounds, soHashMap<Y, i8>
doesn't implementDebug
.That is, your enum needs to implement those two traits, which can be done with
derive
:Closing, but thanks for filing nonetheless!