I have the following definitions:
pub trait PlayerActionFnT: FnMut(&mut State) -> RunState + Send + Sync + 'static {}
impl<F> PlayerActionFnT for F where F: FnMut(&mut State) -> RunState + Send + Sync + 'static {}
pub type PlayerActionFn = Arc<dyn PlayerActionFnT>;
When I try to use this on some mutable global state (gs
), like (action_and_id.action)(gs)
error[E0596]: cannot borrow data in an `Arc` as mutable
--> src/player.rs:294:36
|
294 | Some(action_and_id) => (action_and_id.action)(gs),
| ^^^^^^^^^^^^^^^^^^^^^^ cannot borrow as mutable
|
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Arc<dyn PlayerActionFnT<for<'a> Output = RunState>>`
This is a bit confusing to me, since I'm not trying to mutate what is stored in the Arc
(a function), but rather trying to use it to mutate something I already have mutable access to (gs: &mut State
).