scsys_core/state/traits/
state_repr.rs

1/*
2    appellation: state_repr <module>
3    authors: @FL03
4*/
5use super::RawState;
6
7/// The [`StateRepr`] trait defines the base type for stateful items, allowing for a generic
8/// item type to be associated with the state.
9pub trait StateRepr {
10    type Item: RawState;
11
12    private!();
13}
14
15/*
16 ************* Implementations *************
17*/
18use crate::state::{State, StateBase};
19
20impl<Q> StateRepr for State<Q>
21where
22    Q: RawState,
23{
24    type Item = Q;
25
26    seal!();
27}
28
29impl<Q, K> StateRepr for StateBase<Q, K>
30where
31    Q: RawState,
32{
33    type Item = Q;
34
35    seal!();
36}
37
38macro_rules! impl_state_repr {
39    (@impl $($t:ident)::*<$T:ident>) => {
40        // impl<$T> $crate::state::RawState for $($t)::*<$T>
41        // where
42        //     $T: $crate::state::RawState,
43        // {
44        //     seal!();
45        // }
46
47        impl<$T> $crate::state::StateRepr for $($t)::*<$T>
48        where
49            $T: $crate::state::RawState,
50        {
51            type Item = $T;
52
53            seal!();
54        }
55    };
56    (
57        $(
58            $($t:ident)::*<$T:ident>
59        ),* $(,)?
60    ) => {
61        $(
62            impl_state_repr!(@impl $($t)::*<$T>);
63        )*
64    };
65}
66
67impl_state_repr! {
68    Option<Q>,
69    core::mem::MaybeUninit<Q>,
70    core::marker::PhantomData<Q>,
71}
72
73#[cfg(feature = "alloc")]
74impl_state_repr! {
75    alloc::sync::Arc<Q>,
76    alloc::boxed::Box<Q>,
77    alloc::rc::Rc<Q>,
78    alloc::vec::Vec<Q>,
79}
80
81#[cfg(feature = "std")]
82impl_state_repr! {
83    std::cell::Cell<Q>,
84    std::sync::Mutex<Q>,
85}