I've got an object with a bunch of registered handlers for callback events. I'm getting the error
error[E0596]: cannot borrow `*callback` as mutable, as it is behind a `&` reference
--> src/main.rs:106:33
|
106 | ... (callback)();
| ^^^^^^^^^^ `callback` is a `&` reference, so the data it refers to cannot be borrowed as mutable
Why? I've seen examples where this works and I don't see what I'm doing wrong.
I got this type defined ..
pub enum ObjectCatalog {
String(String),
Callback(Box<dyn FnMut()>),
Mcu(mcu::MCU),
}
pub type VectorOfObjectCatalog = Rc<RefCell<Vec<ObjectCatalog>>>;
In the object, there is a variable of type (below) with a vector of objects that want to know about event X.
event_handlers: HashMap<&'a str, shared_types::VectorOfObjectCatalog>,
In my function that sends out events, it looks like this ...
pub fn send_event(&self, event: &'a str) {
let set = self.event_handlers.get(event);
match set {
Some(vec) => {
for e in vec.borrow().iter() {
match e {
shared_types::ObjectCatalog::Callback(callback) => {
(callback)();
}
_ => {}
}
}
}
None => {}
}
}