mirror of
https://github.com/Zenithsiz/dynatos.git
synced 2026-02-03 10:05:32 +00:00
Added SignalReplace::replace_raw.
This commit is contained in:
parent
ab3d19fc32
commit
b5e22ad328
@ -130,9 +130,15 @@ impl<T: ?Sized + 'static, W: ReactiveWorld> SignalBorrow for Signal<T, W> {
|
||||
impl<T: 'static, W: ReactiveWorld> SignalReplace<T> for Signal<T, W> {
|
||||
type Value = T;
|
||||
|
||||
#[track_caller]
|
||||
fn replace(&self, new_value: T) -> Self::Value {
|
||||
mem::replace(&mut self.borrow_mut(), new_value)
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
fn replace_raw(&self, new_value: T) -> Self::Value {
|
||||
mem::replace(&mut self.borrow_mut_raw(), new_value)
|
||||
}
|
||||
}
|
||||
|
||||
/// Triggers on `Drop`
|
||||
|
||||
@ -6,4 +6,7 @@ pub trait SignalReplace<T> {
|
||||
|
||||
/// Replaces the signal value, returning the previous value
|
||||
fn replace(&self, new_value: T) -> Self::Value;
|
||||
|
||||
/// Replaces the signal value, returning the previous value without triggering any dependencies.
|
||||
fn replace_raw(&self, new_value: T) -> Self::Value;
|
||||
}
|
||||
|
||||
@ -167,6 +167,11 @@ where
|
||||
fn replace(&self, new_value: T) -> Self::Value {
|
||||
self.inner.replace(Some(new_value)).unwrap_or(self.default)
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
fn replace_raw(&self, new_value: T) -> Self::Value {
|
||||
self.inner.replace_raw(Some(new_value)).unwrap_or(self.default)
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, T> SignalReplace<Option<T>> for WithDefault<S, T>
|
||||
@ -180,6 +185,11 @@ where
|
||||
fn replace(&self, new_value: Option<T>) -> Self::Value {
|
||||
self.inner.replace(new_value).unwrap_or(self.default)
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
fn replace_raw(&self, new_value: Option<T>) -> Self::Value {
|
||||
self.inner.replace_raw(new_value).unwrap_or(self.default)
|
||||
}
|
||||
}
|
||||
|
||||
/// Reference type for [`SignalBorrowMut`] impl
|
||||
|
||||
@ -119,6 +119,11 @@ where
|
||||
fn replace(&self, new_value: Vec<T>) -> Self::Value {
|
||||
mem::replace(&mut self.borrow_mut(), new_value)
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
fn replace_raw(&self, new_value: Vec<T>) -> Self::Value {
|
||||
mem::replace(&mut self.borrow_mut_raw(), new_value)
|
||||
}
|
||||
}
|
||||
|
||||
/// Updates the location on `Drop`
|
||||
|
||||
@ -116,6 +116,11 @@ where
|
||||
fn replace(&self, new_value: Option<T>) -> Self::Value {
|
||||
mem::replace(&mut self.borrow_mut(), new_value)
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
fn replace_raw(&self, new_value: Option<T>) -> Self::Value {
|
||||
mem::replace(&mut self.borrow_mut_raw(), new_value)
|
||||
}
|
||||
}
|
||||
|
||||
/// Updates the location on `Drop`
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user