scsys_core/state/
mod.rs

1/*
2    Appellation: state <module>
3    Contrib: FL03 <jo3mccain@icloud.com>
4*/
5//! # State
6//!
7//! This module contains the stateful types and traits for the library.
8#[doc(inline)]
9pub use self::nstate::{NState, NStateKind};
10/// this module implements an alternative stateful representation that enables one to provide
11/// a data type as well as specify the state _kind_
12pub mod nstate;
13
14mod impls {
15    pub mod impl_ops;
16    pub mod impl_repr;
17    pub mod impl_state;
18}
19
20pub(crate) mod prelude {
21    #[doc(inline)]
22    pub use super::nstate::*;
23    #[doc(inline)]
24    pub use super::{RawState, Stateful};
25}
26
27/// [`State`] is a generic type wrapper materializing the [`RawState`] trait.
28#[derive(Clone, Copy, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
29#[cfg_attr(
30    feature = "serde",
31    derive(serde::Deserialize, serde::Serialize),
32    serde(default, transparent)
33)]
34#[repr(transparent)]
35pub struct State<Q = usize>(pub Q);
36
37/// a trait for denoting stateful entities
38pub trait Stateful {
39    type State: RawState;
40}
41
42/// [RawState]
43pub trait RawState {
44    type Item;
45
46    private!();
47}
48
49/*
50 ************* Implementations *************
51*/
52impl<Q, T> RawState for NState<Q, T> {
53    type Item = T;
54
55    seal!();
56}
57
58impl<Q, T> Stateful for NState<Q, T> {
59    type State = NState<Q, T>;
60}