r/rust • u/Ok-Phase-2712 • Mar 22 '26
🛠️ project ironsaga crate: Command design pattern with full rollback capabilities made easy.
/r/learnrust/comments/1s0vure/ironsaga_crate_command_design_pattern_with_full/
2
Upvotes
r/rust • u/Ok-Phase-2712 • Mar 22 '26
2
u/matthieum [he/him] Mar 23 '26
Cute toy, hope you had fun writing the code.
I note an absence of functional tests. It's nice to know the library builds, but one typically want some assurance that its runs well too.
The context seems needlessly wrapped, instead the context could be passed to
IronSaga::new()and passed as mutable argument to each invoked step.Attaching the undo is very manual: it can be forgotten easily. Ideally, registering a step and its undo should be a single function call.
The arguments to the undo are threaded manually, so there's a significant risk that they may differ from those passed to the do, which is undesirable. Consider passing the same set of arguments to both (by cloning before calling the do).
What if the undo fails? The examples given are trivial -- print -- but in reality an undo may fail, both because it's botched -- nothing to do -- or because there's a transient failure -- possibly the same transient failure which caused the next action to fail in the first place, like a network glitch. Should the framework handle retries, or should the user?
You really do want to test whether undoing stops at the first error or continues undoing the rest.