4 releases
Uses old Rust 2015
0.1.3 | Jul 4, 2017 |
---|---|
0.1.2 | Jul 4, 2017 |
0.1.1 | Jul 4, 2017 |
0.1.0 | Jul 4, 2017 |
#80 in #error-handling
26 downloads per month
6KB
116 lines
This library implements parts Saga system for execution and rollback consectual steps.
The basic concept of this installation is that each Saga is made of a number of Adventures. Each Adventure has a forward and backwards step.
When a forward step returns a Failure, the state of that is passed to the backwards step of this and all prior ones
// f1 -> f2 -> f3
// | error
// v
// b1 <- b2 <- b3
An simple example of a saga would be the following:
use aud::Adventure;
use aud::Failure;
use aud::Saga;
use std::error::Error;
use std::fmt;
#[derive(Debug)]
pub struct StupidError {
stupid: bool,
}
impl Error for StupidError {
fn description(&self) -> &str {
"stupid error"
}
}
impl fmt::Display for StupidError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "is stupid: {}", self.stupid)
}
}
fn inc2(i: i32) -> Result<i32, Failure<i32>> {
Ok(i + 1)
}
fn dec(i: i32) -> i32 {
i - 1
}
fn main() {
let saga = Saga::new(vec![
Adventure::new(inc2,dec),
Adventure::new(inc2,dec),
]);
match saga.tell(0) {
Ok(res) => assert!(res == 2),
Err(_) => unimplemented!(),
}
}