scsys_core/state/impls/
impl_repr.rs

1/*
2    Appellation: impl_repr <module>
3    Contrib: @FL03
4*/
5use crate::state::State;
6
7impl<'a, T> State<&'a T> {
8    /// returns a new instance containing a clone of the inner value
9    pub fn cloned(&self) -> State<T>
10    where
11        T: Clone,
12    {
13        State(self.0.clone())
14    }
15    /// returns a new instance containing a copy of the inner value
16    pub fn copied(&self) -> State<T>
17    where
18        T: Copy,
19    {
20        State(*self.0)
21    }
22}
23
24impl<'a, T> State<&'a mut T> {
25    /// returns a new instance containing a clone of the inner value
26    pub fn cloned(&self) -> State<T>
27    where
28        T: Clone,
29    {
30        State(self.0.clone())
31    }
32    /// returns a new instance containing a copy of the inner value
33    pub fn copied(&self) -> State<T>
34    where
35        T: Copy,
36    {
37        State(*self.0)
38    }
39}
40
41impl<T> State<*const T> {}
42
43impl<T> State<core::mem::MaybeUninit<T>> {
44    /// returns a new instance containing a reference to the inner value
45    pub fn unit() -> State<core::mem::MaybeUninit<T>> {
46        State(core::mem::MaybeUninit::uninit())
47    }
48}
49
50impl<T> State<Option<T>> {
51    /// returns a new state with a [`None`](Option::None) inner state
52    pub fn none() -> State<Option<T>> {
53        State(None)
54    }
55    /// returns a new instance with some inner state
56    pub fn some(value: T) -> State<Option<T>> {
57        State(Some(value))
58    }
59
60    pub fn is_none(&self) -> bool {
61        self.get().is_none()
62    }
63}