roopes-core 0.1.1

Roopes is a Rust Object Oriented Pattern Element System. This crate provides generic traits and implementations for typical object-oriented patterns in Rust. It is intended to be used as a cluster of utility classes for implementing OOP-architected executables -- in Rust!
Documentation
//!
#![cfg_attr(feature = "doc-images",
  cfg_attr(
    all(),
    doc = ::embed_doc_image::embed_image!(
        "state-diagram",
        "src/patterns/state/state.svg"
)))]
//! This module implements the State pattern.
//!
//! ![state diagram][state-diagram]

pub mod simple;

/// This trait holds the active state, and acts as
/// a persistent handle for the state machine,
/// which could otherwise be the states
/// themselves.
pub trait Context<S>
where
    S: State,
{
    /// Delegates the state transition to the
    /// currently active state held by the
    /// context, probably triggering a state
    /// change by the context.
    fn handle(&mut self);
}

/// Provides transitions between states.
pub trait State
{
    /// Allow the state to engage in whatever
    /// processing it would normally do.
    /// The returned [`State`] is used to
    /// determine the new state the
    /// [`Context`] should assume.
    #[must_use]
    fn execute(&self) -> Self;
}

/// Exposes the [`Context`] and [`State`] types at
/// the library level.
pub mod prelude
{
    pub use super::{
        Context,
        State,
    };
}

#[cfg(test)]
mod tests;