今天在写rust的时候发现了一个RefCell的使用场景。就是在b持有a的所有权,而a的可变方法中又借用b的时候,这么写是通不过借用检查的:
struct Foo;
struct Bar {
foo: Foo,
msg: String,
}
impl Foo {
fn foo(&mut self, bar: &Bar) {
println!("{}", bar.msg);
}
}
impl Bar {
fn new(foo: Foo) -> Self {
Self