rskit-stateful 0.2.0-alpha.1

Stateful accumulators with triggers, measurers, and TTL cleanup
Documentation

rskit-stateful — State Machines and Accumulators

Stateful accumulation primitives with pluggable stores, configurable flush triggers, size limits, TTL expiration, and keyed manager cleanup.

CI crates.io docs.rs License: MIT MSRV: 1.91

Features

  • StateMachine<S, C> for guarded typed transitions with audit and persistence hooks
  • Transition<S, C> for named transitions with optional guards and actions
  • Accumulator<V> for buffered append/flush workflows
  • AccumulatorConfig<V> with TTL, keep-alive, max-size, triggers, and custom measurers
  • Trigger<V> implementations for size, byte-size, and time-based flushes
  • MemoryStore<V> plus a Store<V> trait for custom backends
  • Manager<K, V> for per-key accumulators and expiration cleanup

Usage

[dependencies]
rskit-stateful = "0.2.0-alpha.1"
use std::sync::Arc;
use std::time::Duration;

use rskit_stateful::{Accumulator, AccumulatorConfig, MemoryStore, SizeTrigger};

let accumulator = Accumulator::new(
    Box::new(MemoryStore::<u32>::new()),
    AccumulatorConfig::new()
        .with_max_size(1_000)
        .with_ttl(Duration::from_secs(30))
        .with_trigger(Arc::new(SizeTrigger::new(3))),
);

assert!(accumulator.append(1)?.is_none());
assert!(accumulator.append(2)?.is_none());
assert_eq!(accumulator.append(3)?, Some(vec![1, 2, 3]));
# Ok::<(), rskit_errors::AppError>(())

Key types

  • StateMachine<S, C> — apply typed guarded transitions and record an audit log
  • Accumulator<V> — append values, flush manually, or flush when triggers fire
  • AccumulatorConfig<V> — builder for TTL, keep-alive, max-size, triggers, and measurer
  • Manager<K, V> — route values to keyed accumulators and clean up expired entries
  • Store<V> — backend abstraction for buffered values
  • MemoryStore<V> — in-memory store implementation
  • CountMeasurer, ByteSizeMeasurer — built-in size measurement strategies

See also

Main repository README