比较Ref与PartialEq的内容

问题描述 投票:0回答:1

假设我有两个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);
}
rust
1个回答
1
投票

std::cell::Ref实现std::cell::Ref,您需要使用它来使用std::ops::Deref运算符获取值本身。使用您的摘要,您想做

std::ops::Deref

(C0])

© www.soinside.com 2019 - 2024. All rights reserved.