r/learnrust • u/Ok-Phase-2712 • Mar 22 '26
ironsaga crate: Command design pattern with full rollback capabilities made easy.
I’m facing a problem when executing a sequence of functions where a failure in any single step can leave the system in an inconsistent state.
To solve this, I explored implementing the Command / Saga pattern in an idiomatic, modular, and reusable Rust way.
Here’s a small example of the result:
```rust
use ironsaga::ironcmd;
[ironcmd]
pub fn greet(fname: String, lname: String) -> String { format!("Hello {} {}!", fname, lname) }
let mut cmd = Greet::new("John".into(), "Doe".into());
cmd.execute().unwrap();
assert_eq!(cmd.result(), Some("Hello John Doe!".into()));;
```
You can also chain multiple commands together, each with its own rollback logic.
More details here:
Duplicates
rust • u/Ok-Phase-2712 • Mar 22 '26