假设我有两个Ref<T>对象,其中T实现了PartialEq,如何比较它们?
Ref<T>
T
PartialEq
以下内容无效:
use std::cell::RefCell; fn main() { let a = RefCell::new("abcdef".to_string()).borrow(); let b = RefCell::new("abcdef".to_string()).borrow(); println!("{}", a == b); }
std::cell::Ref实现std::cell::Ref,您需要使用它来使用std::ops::Deref运算符获取值本身。使用您的摘要,您想做
std::cell::Ref
std::ops::Deref
(C0])