scsys_core/state/
nstate.rs1#[doc(inline)]
6pub use self::kind::*;
7
8mod kind;
9
10use core::marker::PhantomData;
11
12pub type NaryState<T, const N: usize = 4> = NState<Nary<N>, T>;
14
15#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
18#[cfg_attr(
19 feature = "serde",
20 derive(serde::Deserialize, serde::Serialize),
21 serde(default)
22)]
23pub struct NState<K, V> {
24 pub(crate) data: V,
25 pub(crate) _state: PhantomData<K>,
26}
27
28impl<K, V> NState<K, V> {
29 pub fn new(data: V) -> Self {
30 Self {
31 data,
32 _state: PhantomData::<K>,
33 }
34 }
35
36 pub fn data(&self) -> &V {
37 &self.data
38 }
39
40 pub fn is_state<R: 'static>(&self) -> bool
41 where
42 K: 'static,
43 {
44 use core::any::TypeId;
45 TypeId::of::<PhantomData<K>>() == TypeId::of::<PhantomData<R>>()
46 }
47}