reactive_signals/signals/types/
func.rs

1use super::{Readable, SignalType};
2
3/// A function that produces a value that doesn't implement [PartialEq]
4pub struct Func<T>(pub(crate) T);
5
6impl<T> Readable for Func<T> {}
7
8impl<T: 'static> SignalType for Func<T> {
9    type Inner = T;
10
11    fn inner(&self) -> &Self::Inner {
12        &self.0
13    }
14    fn inner_mut(&mut self) -> &mut Self::Inner {
15        &mut self.0
16    }
17    fn new(value: Self::Inner) -> Self {
18        Self(value)
19    }
20}
21
22/// A function that produces a value that implements [PartialEq]
23pub struct EqFunc<T>(pub(crate) T);
24
25impl<T> Readable for EqFunc<T> {}
26
27impl<T: 'static + PartialEq> SignalType for EqFunc<T> {
28    type Inner = T;
29
30    fn is_eq(&self, other: &Self::Inner) -> bool {
31        self.0 == *other
32    }
33
34    fn inner(&self) -> &Self::Inner {
35        &self.0
36    }
37    fn inner_mut(&mut self) -> &mut Self::Inner {
38        &mut self.0
39    }
40    fn new(value: Self::Inner) -> Self {
41        Self(value)
42    }
43}