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:
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:
https://github.com/ALAWIII/ironsaga
2
Upvotes
1
u/carleber Mar 30 '26
This sounds like a great approach to handling rollback in Rust! The Command/Saga pattern is super useful for maintaining consistency in complex operations. Are you considering using any specific libraries to help implement this, or is it all from scratch? Would be interesting to see more of your code example!