不能从RefCell <fnmut>中可靠地借用

时间:2017-11-12 18:48:20

标签: rust lifetime borrow-checker borrowing

我遇到了大量代码的问题而我看不出问题是什么

use std::rc::Rc;
use std::cell::RefCell;

struct Order {
    id: u64,
}

fn main() {
    respond(
        Order { id: 0 },
        Rc::new(RefCell::new(|ord| {
            ord;
            ()
        })),
    );
}

fn respond(order: Order, func: Rc<RefCell<FnMut(Order) -> ()>>) -> () {
    let mut caller = func.borrow_mut();
    caller(order);
}

playground

编译器说:

error[E0596]: cannot borrow immutable borrowed content as mutable
  --> src/main.rs:20:5
   |
20 |     caller(order);
   |     ^^^^^^ cannot borrow as mutable

0 个答案:

没有答案