Cannot borrow mutably from a RefCell<FnMut>


I am having an issue passing around an FnMut, I do not understand exactly why this does not compile

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

error[E0596]: cannot borrow immutable borrowed content as mutable
  --> src/
15 |                 caller(order);
   |                 ^^^^^^ cannot borrow as mutable

playground link: playground


Found the issue detailed here github

I solved it by calling it like:

(&mut *func.borrow_mut())(order);

It looks horrible though


You need to get the &mut FnMut out of the RefMut that borrow_mut returns:

let caller = &mut *func.borrow_mut();


This was cross-posted to Stack Overflow