pipecircuit-cli 0.0.2

Command-line architectural tools for Pipecircuit programs
use app_core::{
    domain_primitives::{Amount, Count},
    state_machines::{Add, AddOutcome, Counter, Read},
};
use pipecircuit::{Pipe, StateMachine, StepInputOf};

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Request {
    Add(Amount),
    Read,
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Reply {
    Added(AddOutcome),
    Snapshot(Count),
}

pub struct Client;

impl Pipe for Client {
    type In<'message> = Reply;
    type Out<'message> = Request;
}

pub struct Counting;

impl Pipe for Counting {
    type In<'message> = Request;
    type Out<'message> = Reply;
}

pub struct CounterAuthority(Counter);

impl CounterAuthority {
    pub const fn new(counter: Counter) -> Self {
        Self(counter)
    }
}

impl StateMachine for CounterAuthority {}

impl StepInputOf<CounterAuthority> for Request {
    type Outcome = Reply;

    fn step(self, authority: &mut CounterAuthority) -> Reply {
        match self {
            Self::Add(amount) => Reply::Added(authority.0.step(Add { amount })),
            Self::Read => Reply::Snapshot(authority.0.step(Read)),
        }
    }
}