Fixed WithDefault not working for signals that yield &Option<T>.

This commit is contained in:
Filipe Rodrigues 2024-12-22 15:17:27 +00:00
parent 91b7927e3b
commit e9f29e1229
Signed by: zenithsiz
SSH Key Fingerprint: SHA256:Mb5ppb3Sh7IarBO/sBTXLHbYEOz37hJAlslLQPPAPaU

View File

@ -65,7 +65,9 @@ impl<S: SignalBorrow, T> SignalBorrow for WithDefault<S, T> {
impl<S, T> SignalWith for WithDefault<S, T>
where
S: for<'a> SignalWith<Value<'a> = Option<&'a T>>,
S: SignalWith,
// Note: This allows both `Option<&'_ T>` and `&'_ Option<T>`
for<'a> S::Value<'a>: Into<Option<&'a T>>,
T: 'static,
{
type Value<'a> = &'a T;
@ -75,13 +77,15 @@ where
where
F: for<'a> FnOnce(Self::Value<'a>) -> O,
{
self.inner.with(|value| match value {
self.inner.with(|value| match value.into() {
Some(value) => f(value),
None => f(&self.default),
})
}
}
// TODO: Impl `SignalGet<Option<T>>` once we can?
impl<S, T> SignalReplace<T> for WithDefault<S, T>
where
S: SignalReplace<Option<T>>,