2

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

3
  • 4
    #[derive(Data)] is not in the Rust's standard library. Which library are you using? Commented Apr 30, 2022 at 3:10
  • 2
    I am using the library druid but the question has been answered by jonathan ! ty Commented Apr 30, 2022 at 3:18
  • 2
    A link to the library: Druid. Commented Apr 30, 2022 at 3:18

1 Answer 1

3

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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.