State

Trait State 

Source
pub trait State:
    Clone
    + PartialEq
    + Debug
    + Serialize
    + for<'de> Deserialize<'de>
    + Send
    + Sync {
    // Required method
    fn name(&self) -> &str;

    // Provided methods
    fn is_final(&self) -> bool { ... }
    fn is_error(&self) -> bool { ... }
}
Expand description

Trait for state machine states.

All methods are pure - no side effects. States represent immutable values that describe the current position in a state machine.

§Required Traits

  • Clone: States must be cloneable for history tracking
  • PartialEq: States must be comparable for transition logic
  • Debug: States must be debuggable for diagnostics
  • Serialize + Deserialize: States must be serializable for persistence

§Example

use mindset::core::State;
use serde::{Deserialize, Serialize};

#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
enum TaskState {
    Pending,
    Running,
    Complete,
    Failed,
}

impl State for TaskState {
    fn name(&self) -> &str {
        match self {
            Self::Pending => "Pending",
            Self::Running => "Running",
            Self::Complete => "Complete",
            Self::Failed => "Failed",
        }
    }

    fn is_final(&self) -> bool {
        matches!(self, Self::Complete | Self::Failed)
    }

    fn is_error(&self) -> bool {
        matches!(self, Self::Failed)
    }
}

Required Methods§

Source

fn name(&self) -> &str

Get the state’s name for display/logging.

Returns a static string reference for zero-cost naming.

Provided Methods§

Source

fn is_final(&self) -> bool

Check if this is a final (terminal) state.

Final states represent completion points in the state machine where no further transitions are expected.

Default implementation returns false.

Source

fn is_error(&self) -> bool

Check if this is an error state.

Error states represent failure conditions in the state machine. They are typically also final states, but this is not enforced.

Default implementation returns false.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§