Added SignalReplace::replace_raw.

This commit is contained in:
Filipe Rodrigues 2025-05-16 17:52:29 +01:00
parent ab3d19fc32
commit b5e22ad328
Signed by: zenithsiz
SSH Key Fingerprint: SHA256:Mb5ppb3Sh7IarBO/sBTXLHbYEOz37hJAlslLQPPAPaU
5 changed files with 29 additions and 0 deletions

View File

@ -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`

View File

@ -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;
}

View File

@ -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

View File

@ -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`

View File

@ -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`