use crate::{netmod::Target, types::Frame, Result};
use async_trait::async_trait;
use std::sync::Arc;
#[async_trait]
pub trait Endpoint {
async fn start_peering(&self, _addr: &str) -> Result<u16> {
unimplemented!()
}
fn size_hint(&self) -> usize;
async fn send(&self, frame: Frame, target: Target, exclude: Option<u16>) -> Result<()>;
async fn next(&self) -> Result<(Frame, Target)>;
}
#[async_trait]
impl<T: Endpoint + Send + Sync> Endpoint for Arc<T> {
fn size_hint(&self) -> usize {
T::size_hint(self)
}
async fn send(&self, frame: Frame, target: Target, exclude: Option<u16>) -> Result<()> {
T::send(self, frame, target, exclude).await
}
async fn next(&self) -> Result<(Frame, Target)> {
T::next(self).await
}
}