pub trait StateMutation<S>:
Sized
+ Send
+ Sync
+ Debug {
// Required method
fn apply(self, state: &mut S);
// Provided method
fn combine(self, _other: Self) -> Option<Self> { ... }
}Expand description
状态变更命令 — 描述一次对 State 的确定性修改。
Mutation 自己知道如何修改对应的 State(apply(self, &mut S))。
State 只是数据,Mutation 是变更逻辑,Executor 负责调度。
§设计原则
- Command 而非 Patch:
AppendMessage而非SetMessages - Enum 分发:顶层 enum 只做一层 match,具体逻辑在各 variant 的
apply()中 - 无 Serialize 强制:只有需要 Replay 的运行时才加
Serializebound
Required Methods§
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".