use super::{BoxedPlan, Declined, Plan, PlanTree};
pub trait Step<I> {
fn apply(&self, inputs: &I) -> Result<I, Declined>;
fn name(&self) -> String;
}
pub struct Then<I, O> {
step: Box<dyn Step<I> + Send + Sync>,
plan: BoxedPlan<I, O>,
}
impl<I, O> Then<I, O> {
pub fn new(step: impl Step<I> + Send + Sync + 'static, plan: BoxedPlan<I, O>) -> Self {
Self {
step: Box::new(step),
plan,
}
}
}
impl<I, O> Plan<I> for Then<I, O> {
type Output = O;
fn launch(&self, inputs: &I) -> Result<O, Declined> {
self.plan.launch(&self.step.apply(inputs)?)
}
fn tree(&self) -> PlanTree {
PlanTree::Then {
step: self.step.name(),
plan: Box::new(self.plan.tree()),
}
}
}