1 unstable release
Uses new Rust 2024
| 0.1.1 | Jun 7, 2025 |
|---|---|
| 0.1.0 |
|
#15 in #slot
7KB
107 lines
XTState
XTState is a flexible, thread-safe Rust library for managing and tracking named boolean slots and their activation history. It is useful for feature flag management, workflow tracking, distributed system coordination, and event synchronization, providing a simple API and timestamped state changes.
lib.rs:
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
activatedfield. - Thread-safe usage via the
ThreadSafeXTStatetype 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
chronocrate for timestamping history entries.
Thread Safety
Use the ThreadSafeXTState type alias for safe sharing and mutation across threads.
Dependencies
~1MB
~18K SLoC