Relax dynamic source requirement from Fn to FnMut

This commit is contained in:
CordlessCoder 2025-09-17 01:23:25 +01:00 committed by Callum Leslie
parent 4dd7df50e1
commit bb5950cd76
2 changed files with 4 additions and 4 deletions

View file

@ -117,9 +117,9 @@ where
}
fn handle_get_value(&self) -> Result<Response<T>, Error> {
let state = self.state.lock().map_err(|_| Error::InternalError)?;
let mut state = self.state.lock().map_err(|_| Error::InternalError)?;
match &*state {
match &mut *state {
ValueSource::Static(value) => Ok(Response::Value(value.clone())),
ValueSource::Dynamic(closure) => {
let value = self.execute_closure_safely(closure);
@ -135,7 +135,7 @@ where
fn execute_closure_safely(
&self,
closure: &dyn Fn() -> T,
closure: &mut dyn FnMut() -> T,
) -> Result<T, Box<dyn std::any::Any + Send>> {
std::panic::catch_unwind(std::panic::AssertUnwindSafe(closure))
}

View file

@ -16,7 +16,7 @@ pub enum Response<T> {
/// Represents the source of values: either static or dynamic
pub(crate) enum ValueSource<T> {
Static(T),
Dynamic(Box<dyn Fn() -> T + Send + Sync + 'static>),
Dynamic(Box<dyn FnMut() -> T + Send + Sync + 'static>),
None, // Never set
Cleared, // Was set but cleared (closed)
}