Crate aud [] [src]

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!(),
        }
    }

Structs

Adventure

An adventure that can can forward succeed or fail and be reverted. Make sure that a failure includes enough info for THIS step itsel to be reverted

Failure

A simple failure that can return an error along with the new state.

Saga

A sage of many adventures that can be told.