rstm_state/
lib.rs

1/*
2    Appellation: rstm-state <library>
3    Created At: 2025.08.29:22:43:22
4    Contrib: @FL03
5*/
6//! The [`state`](self) module provides abstractions and implementations for managing state
7//! within the `rstm` framework.
8//!
9#![allow(
10    clippy::missing_safety_doc,
11    clippy::module_inception,
12    clippy::needless_doctest_main,
13    clippy::self_named_constructors,
14    clippy::should_implement_trait
15)]
16#![cfg_attr(not(feature = "std"), no_std)]
17#![cfg_attr(feature = "nightly", feature(allocator_api))]
18
19#[cfg(feature = "alloc")]
20extern crate alloc;
21
22#[macro_use]
23mod macros {
24    #[macro_use]
25    pub(crate) mod seal;
26    #[macro_use]
27    pub(crate) mod state;
28}
29
30#[doc(inline)]
31pub use self::{error::*, state::State, traits::*, types::*};
32
33mod state;
34
35pub mod error;
36
37mod impls {
38    mod impl_state;
39    mod impl_state_ops;
40    mod impl_state_repr;
41
42    #[allow(deprecated)]
43    mod impl_state_deprecated;
44}
45
46pub mod traits {
47    //! the traits for defining the types of states and their behaviors
48    #[doc(inline)]
49    pub use self::prelude::*;
50
51    mod halting;
52    mod raw_state;
53    mod stateful;
54
55    mod prelude {
56        #[doc(inline)]
57        pub use super::halting::*;
58        #[doc(inline)]
59        pub use super::raw_state::*;
60        #[doc(inline)]
61        pub use super::stateful::*;
62    }
63}
64
65pub mod types {
66    //! various types and type aliases for working with state
67    #[doc(inline)]
68    pub use self::prelude::*;
69
70    mod halter;
71
72    mod prelude {
73        #[doc(inline)]
74        pub use super::aliases::*;
75        #[doc(inline)]
76        pub use super::halter::*;
77    }
78
79    mod aliases {
80        use crate::state::State;
81        #[cfg(feature = "alloc")]
82        /// A type alias for a [State] whose inner value is the dynamically sized type of a
83        /// boxed [`Any`](core::any::Any).
84        pub type AnyState = State<alloc::boxed::Box<dyn core::any::Any>>;
85        /// A type alias for a [State] whose inner value is a [core::mem::MaybeUninit] of
86        /// generic type `Q`.
87        pub type MaybeState<Q = bool> = State<core::mem::MaybeUninit<Q>>;
88        #[cfg(feature = "alloc")]
89        pub type SharedState<Q> = State<alloc::sync::Arc<Q>>;
90        #[cfg(feature = "std")]
91        pub type ShardState<Q> = State<std::sync::Arc<std::sync::Mutex<Q>>>;
92        /// A type alias for a [State] whose inner value is a reference to a generic type `Q`.
93        pub type RefState<'a, Q> = State<&'a Q>;
94        /// A type alias for a [State] whose inner value is a mutable reference to a generic
95        ///  type `Q`.
96        pub type MutState<'a, Q> = State<&'a mut Q>;
97        /// A type alias for a [State] whose inner value is a raw pointer to a generic type `Q`
98        pub type PtrState<Q> = State<*mut Q>;
99    }
100}
101
102#[doc(hidden)]
103pub mod prelude {
104    pub use crate::state;
105    #[doc(no_inline)]
106    pub use crate::state::*;
107    #[doc(no_inline)]
108    pub use crate::traits::*;
109    #[doc(no_inline)]
110    pub use crate::types::*;
111}