mirror of
https://github.com/callumio/suck.git
synced 2025-12-17 03:29:21 +00:00
Relax dynamic source requirement from Fn to FnMut
This commit is contained in:
parent
4dd7df50e1
commit
061a45eaa8
2 changed files with 4 additions and 4 deletions
|
|
@ -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))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue