mirror of
https://github.com/callumio/suck.git
synced 2025-12-19 20:39:21 +00:00
Relax T: Clone bound to only apply to static values
This commit is contained in:
parent
7c8fc42f27
commit
4c13facc96
2 changed files with 17 additions and 5 deletions
|
|
@ -63,13 +63,19 @@ where
|
|||
|
||||
impl<T, SR, ST> Sourcer<T, SR, ST>
|
||||
where
|
||||
T: Clone + Send + 'static,
|
||||
T: Send + 'static,
|
||||
SR: ChannelReceiver<Request>,
|
||||
ST: ChannelSender<Response<T>>,
|
||||
{
|
||||
/// Set a fixed value
|
||||
pub fn set_static(&self, value: T) -> Result<(), Error> {
|
||||
self.state.swap(Arc::new(ValueSource::Static(value)));
|
||||
pub fn set_static(&self, val: T) -> Result<(), Error>
|
||||
where
|
||||
T: Clone,
|
||||
{
|
||||
self.state.swap(Arc::new(ValueSource::Static {
|
||||
val,
|
||||
clone: T::clone,
|
||||
}));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -130,7 +136,13 @@ where
|
|||
let state = self.state.load();
|
||||
|
||||
match &**state {
|
||||
ValueSource::Static(value) => Ok(Response::Value(value.clone())),
|
||||
ValueSource::Static { val, clone } => {
|
||||
let value = self.execute_closure_safely(&mut || clone(val));
|
||||
match value {
|
||||
Ok(v) => Ok(Response::Value(v)),
|
||||
Err(_) => Ok(Response::NoSource), // Closure execution failed
|
||||
}
|
||||
}
|
||||
ValueSource::Dynamic(closure) => {
|
||||
let value = self.execute_closure_safely(&mut || closure());
|
||||
match value {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue