1use crate::storage::Storage;
2use async_trait::async_trait;
3
4#[cfg_attr(not(all(doc, not(doctest))), async_trait)]
5pub trait Node<Input, Output, Error> {
6 async fn run_with_storage<'input>(
7 &mut self,
8 input: Input,
9 storage: &mut Storage,
10 ) -> Result<Output, Error>
11 where
12 Input: 'input;
13}
14
15#[derive(Debug, PartialEq, Eq)]
16pub enum NodeOutput<T> {
17 SoftFail,
18 Ok(T),
19}
20
21#[macro_export]
22macro_rules! impl_node_output {
23 ($node:ty, $input:ty, $output:ty, $error:ty) => {
24 #[cfg_attr(not(all(doc, not(doctest))), $crate::async_trait::async_trait)]
25 impl $crate::node::Node<$input, $crate::node::NodeOutput<$output>, $error> for $node {
26 async fn run_with_storage<'input>(
27 &mut self,
28 input: $input,
29 storage: &mut $crate::storage::Storage,
30 ) -> Result<$crate::node::NodeOutput<$output>, $error> {
31 Ok($crate::node::NodeOutput::Ok(
32 <Self as $crate::node::Node<$input, $output, $error>>::run_with_storage(
33 self, input, storage,
34 )
35 .await?,
36 ))
37 }
38 }
39 };
40}