Grandma Kisses
Grandma Kisses

Reputation: 55

How to make a type of hash map with struct in rust

I am new to rust and I am looking to implement my hashmap in my struct like so

#[derive(Clone, Data)]
struct CheckState { 
    cool: String,
    int_cool: i32,
    hashmap_cool: HashMap<i32, String>
}

But i keep recieving the error code error[E0277]: the trait bound `HashMap<i32, std::string::String>: Data` is not satisfied and i do not understand why and the help is not much help

the rust help

 help: the following other types implement trait `Data`:
            &'static str
            ()
            (T0, T1)
            (T0, T1, T2)
            (T0, T1, T2, T3)
            (T0, T1, T2, T3, T4)
            (T0, T1, T2, T3, T4, T5)
            (T0,)
          and 87 others
  = note: this error originates in the derive macro `Data` (in Nightly builds, run with -Z macro-backtrace for more info)

please ignore variable names they are not the same in my code

Upvotes: 2

Views: 1434

Answers (1)

Jonathan Coletti
Jonathan Coletti

Reputation: 528

For a simple fix add:

struct CheckState { 
    cool: String,
    int_cool: i32,
    #[data(ignore)]
    hashmap_cool: HashMap<i32, String>
}

See the druid documentation for a better understanding:

  • #[data(ignore)] makes the generated Data::same function skip comparing this field.

Upvotes: 3

Related Questions