如何制作带有struct in rust的哈希地图

发布于 2025-01-25 04:22:21 字数 810 浏览 3 评论 0原文

我是Rust的新手,我希望像这样在结构中实现我的hashmap,

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

但是我一直在收回错误代码错误[E0277]:特征绑定了`hashmap&lt; i32,std :: string :: string :: string&gt;::: string&gt; ::数据“不满足,我不明白为什么,帮助没有太大帮助的

生锈,

 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)

请忽略变量名称,它们在我的代码中并不相同

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热风软妹 2025-02-01 04:22:21

有关简单的修复添加:

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

请参阅 druid文档更好的理解:

  • ##[data(nighore)]使生成的data :: Same函数跳过比较此字段的功能。

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文