Crate xtstate

Crate xtstate 

Source
Expand description

§XTState

XTState is a flexible, thread-safe state management utility for tracking named boolean slots and their activation history in Rust.

§Features

  • Track multiple named boolean slots (flags) and their states.
  • Record a timestamped history of all slot changes.
  • Determine when all slots are active (true) via the activated field.
  • Thread-safe usage via the ThreadSafeXTState type alias (Arc<Mutex<XTState>>).

§Example Usage

use xtstate::{XTState, ThreadSafeXTState};
use std::collections::HashSet;
use std::sync::{Arc, Mutex};

// Create a new XTState
let mut xt = XTState::new();
xt.setup_slots(HashSet::from(["slot1".to_string(), "slot2".to_string()]), false);
xt.update_callback("slot1".to_string(), true);
xt.update_callback("slot2".to_string(), true);
assert!(xt.activated);

// Thread-safe usage
let state: ThreadSafeXTState = Arc::new(Mutex::new(XTState::new()));
{
    let mut xt = state.lock().unwrap();
    xt.setup_slots(HashSet::from(["slot1".to_string(), "slot2".to_string()]), false);
}
// ... spawn threads and update slots ...

§Use Cases

  • Feature flag management
  • Workflow or step completion tracking
  • Distributed system readiness coordination
  • Event synchronization

§Crate Features

  • Requires the chrono crate for timestamping history entries.

§Thread Safety

Use the ThreadSafeXTState type alias for safe sharing and mutation across threads.

Structs§

XTState

Type Aliases§

ThreadSafeXTState