#[doc(inline)]
pub use self::{nstate::StateBase, traits::prelude::*, types::prelude::*, wrapper::State};
pub mod nstate;
pub mod wrapper;
mod impls {
pub mod impl_wrapper;
pub mod impl_wrapper_ops;
}
pub mod traits {
#[doc(inline)]
pub use self::prelude::*;
pub mod kind;
pub mod state;
pub mod state_repr;
pub mod stateful;
pub(crate) mod prelude {
#[doc(inline)]
pub use super::kind::*;
#[doc(inline)]
pub use super::state::*;
#[doc(inline)]
pub use super::state_repr::*;
#[doc(inline)]
pub use super::stateful::*;
}
}
pub mod types {
#[doc(inline)]
pub use self::prelude::*;
pub mod kinds;
pub mod nary;
pub(crate) mod prelude {
#[doc(inline)]
pub use super::aliases::*;
#[doc(inline)]
pub use super::kinds::*;
#[doc(inline)]
pub use super::nary::*;
}
pub(crate) mod aliases {
use crate::state::{Nary, StateBase};
pub type NState<T, const N: usize = 4> = StateBase<T, Nary<N>>;
}
}
pub(crate) mod prelude {
#[doc(inline)]
pub use super::nstate::*;
#[doc(inline)]
pub use super::wrapper::*;
#[doc(inline)]
pub use super::traits::prelude::*;
#[doc(inline)]
pub use super::types::prelude::*;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_state() {
let mut state = State::<usize>::zero();
assert_eq!(state, 0);
state.set(5);
assert_eq!(state, 5);
assert_eq!(state.take(), 5);
assert_eq!(state, 0);
let mapped = state.map(|x| x + 1);
assert_eq!(mapped, 1);
assert_ne!(mapped, state);
}
#[test]
fn test_state_views() {
let mut state = State::<usize>::zero();
let view = state.view();
assert_eq!(view.get(), &&0);
assert_eq!(view.copied(), 0);
state.set(5);
assert_eq!(state.view().value(), &mut 5_usize);
}
#[cfg(feature = "rand")]
#[test]
fn test_random_state() {
let a = State::<f32>::random();
let b = State::<f32>::random();
assert_ne!(a, b);
}
}