Cannot borrow mutably from a RefCell<FnMut>

Viewed 118

I am having an issue with a chunk of code and I fail to see what the problem is

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)

The compiler says:

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