[英]How to make a type of hash map with struct in rust
我是 rust 的新手,我希望像這樣在我的結構中實現我的 hashmap
#[derive(Clone, Data)]
struct CheckState {
cool: String,
int_cool: i32,
hashmap_cool: HashMap<i32, String>
}
但我一直收到錯誤代碼error[E0277]: the trait bound `HashMap<i32, std::string::String>: Data` is not satisfied
,我不明白為什么,幫助也沒什么幫助
rust 幫助
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)
請忽略變量名,它們在我的代碼中不一樣
對於一個簡單的修復添加:
struct CheckState {
cool: String,
int_cool: i32,
#[data(ignore)]
hashmap_cool: HashMap<i32, String>
}
請參閱德魯伊文檔以獲得更好的理解:
#[data(ignore)]
使生成的Data::same
function 跳過比較此字段。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.