4

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
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Arkaitz Jimenez
  • 22,500
  • 11
  • 75
  • 105
  • This was [cross-posted to the user's forum](https://users.rust-lang.org/t/cannot-borrow-mutably-from-a-refcell-fnmut/13836?u=shepmaster). – Shepmaster Nov 12 '17 at 21:40

0 Answers0