我有一个自定义类型:
pub struct PValue {
pub name: String,
pub value: Option<serde_json::Value>,
pub from: Option<String>,
}
pub struct CC {
pub name: String,
pub inst_name: String,
pub pv: Option<Vec<PValue>>,
}
pub struct ComponentRecord {
config: CC,
version: String,
}
let cr = ComponentRecord {
version: "123".to_string(),
config: CC {
name: "n123".to_string(),
instance_name: "inst123".to_string(),
pv: None,
},
};
let newcr = ComponentRecord {
version: "123".to_string(),
config: ComponentConfiguration {
name: "n123".to_string(),
instance_name: "inst123".to_string(),
pv: None,
},
};
assert_eq!(crgot, cr);
然后我遇到了错误:
error[E0369]: binary operation `==` cannot be applied to type `&ComponentRecord`
--> src/xxx_test.rs:39:5
|
39 | assert_eq!(crgot, cr);
| ^^^^^^^^^^^^^^^^^^^^^^
| |
| ComponentRecord
| ComponentRecord
|
= note: an implementation of `std::cmp::PartialEq` might be missing for `&ComponentRecord`
我应该如何测试两个RecordAnnotation
实例是否相等?
我在编写测试,因此不关心性能是否良好。
在golang中,我可以使用reflect.DeepEqual来完成。 我希望在Rust中找到一种通用的方法。
record1 == record2
- Boiethios