pub trait StateSpec:
State
+ Clone
+ Sized
+ Send
+ 'static {
type Action: Serialize + DeserializeOwned + Send + 'static;
const SCOPE: StateScope = StateScope::Thread;
// Required method
fn reduce(&mut self, action: Self::Action);
}Expand description
Extends State with a typed action and a pure reducer.
Implementors define what actions their state accepts and how the state
transitions in response. The kernel applies actions via type-erased
AnyStateAction without knowing the concrete types.
Scope (Run vs ToolCall) is determined at the call site — AnyStateAction::new()
for run-scoped state, AnyStateAction::new_for_call() for tool-call-scoped state —
rather than being encoded in the trait, keeping business semantics out of tirea-state.
§Usage
Typically generated by #[derive(State)] with #[tirea(action = "...")]:
#[derive(State, Clone, Serialize, Deserialize)]
#[tirea(path = "counters.main", action = "CounterAction")]
struct Counter { value: i64 }
impl Counter {
fn reduce(&mut self, action: CounterAction) {
match action {
CounterAction::Increment(n) => self.value += n,
}
}
}Provided Associated Constants§
Sourceconst SCOPE: StateScope = StateScope::Thread
const SCOPE: StateScope = StateScope::Thread
Lifecycle scope of this state type.
Defaults to Thread (never automatically cleaned) for backward
compatibility. Override via #[tirea(scope = "run")] or
#[tirea(scope = "tool_call")] in the derive macro.
Required Associated Types§
Sourcetype Action: Serialize + DeserializeOwned + Send + 'static
type Action: Serialize + DeserializeOwned + Send + 'static
The action type accepted by this state.
Required Methods§
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.