use async_trait::async_trait;
use crate::error::AnchorChainError;
use crate::node::Node;
#[derive(Debug)]
pub struct Link<C, N>
where
C: std::fmt::Debug,
N: std::fmt::Debug,
{
pub node: C,
pub next: N,
}
impl<C, N> Link<C, N>
where
C: std::fmt::Debug,
N: std::fmt::Debug,
{
pub fn new(node: C, next: N) -> Self {
Link { node, next }
}
}
#[async_trait]
impl<C, N> Node for Link<C, N>
where
C: Node + Send + Sync + std::fmt::Debug,
C::Output: Send + 'static,
C::Input: Send,
N: Node<Input = C::Output> + Send + Sync + std::fmt::Debug,
N::Output: Send,
{
type Input = C::Input;
type Output = <N as Node>::Output;
async fn process(&self, input: Self::Input) -> Result<Self::Output, AnchorChainError> {
let output = self.node.process(input).await?;
self.next.process(output).await
}
}