use std::marker::PhantomData;
use async_trait::async_trait;
#[cfg(feature = "tracing")]
use tracing::instrument;
use crate::error::AnchorChainError;
#[async_trait]
pub trait Node: std::fmt::Debug {
type Input;
type Output;
async fn process(&self, input: Self::Input) -> Result<Self::Output, AnchorChainError>;
}
#[derive(Debug)]
pub struct NoOpNode<T> {
_marker: PhantomData<T>,
}
impl<T> NoOpNode<T> {
pub fn new() -> Self {
Self {
_marker: PhantomData,
}
}
}
impl<T> Default for NoOpNode<T> {
fn default() -> Self {
Self::new()
}
}
#[async_trait]
impl<T> Node for NoOpNode<T>
where
T: Send + Sync + std::fmt::Debug,
{
type Input = T;
type Output = T;
#[cfg_attr(feature = "tracing", instrument(skip(self)))]
async fn process(&self, input: Self::Input) -> Result<Self::Output, AnchorChainError> {
Ok(input)
}
}