#![warn(clippy::all)]
#![warn(missing_docs)]
#![doc = include_str!("../README.md")]
pub use aeronet_wt_core_derive::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ChannelKind {
Datagram,
Stream,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ChannelId {
Datagram,
Stream(usize),
}
impl From<ChannelId> for ChannelKind {
fn from(value: ChannelId) -> Self {
match value {
ChannelId::Datagram => Self::Datagram,
ChannelId::Stream(_) => Self::Stream,
}
}
}
pub trait Channels: 'static {
fn channel_id(&self) -> ChannelId;
fn num_streams() -> usize;
}
pub trait OnChannel {
type Channel: Channels;
fn channel(&self) -> Self::Channel;
}
#[derive(Debug, thiserror::Error)]
pub enum ChannelError {
#[error("failed to open channel")]
Open(#[source] anyhow::Error),
#[error("failed to receive data")]
Recv(#[source] anyhow::Error),
#[error("failed to send data")]
Send(#[source] anyhow::Error),
#[error("closed")]
Closed,
}
#[derive(Debug, thiserror::Error)]
#[error("on {channel:?}")]
pub struct OnChannelError {
pub channel: ChannelId,
#[source]
pub source: ChannelError,
}
impl ChannelError {
pub fn on(self, channel: ChannelId) -> OnChannelError {
OnChannelError {
channel,
source: self,
}
}
}