mesh_channel_core/
error.rsuse thiserror::Error;
#[derive(Debug, Error)]
#[error(transparent)]
pub struct ChannelError(Box<ChannelErrorInner>);
#[derive(Debug)]
#[non_exhaustive]
pub enum ChannelErrorKind {
NodeFailure,
Corruption,
}
impl ChannelError {
pub fn kind(&self) -> ChannelErrorKind {
match &*self.0 {
ChannelErrorInner::NodeFailure(_) => ChannelErrorKind::NodeFailure,
ChannelErrorInner::Corruption(_) => ChannelErrorKind::Corruption,
}
}
}
impl From<mesh_protobuf::Error> for ChannelError {
fn from(err: mesh_protobuf::Error) -> Self {
Self(Box::new(ChannelErrorInner::Corruption(err)))
}
}
impl From<mesh_node::local_node::NodeError> for ChannelError {
fn from(value: mesh_node::local_node::NodeError) -> Self {
Self(Box::new(ChannelErrorInner::NodeFailure(value)))
}
}
#[derive(Debug, Error)]
enum ChannelErrorInner {
#[error("node failure")]
NodeFailure(#[source] mesh_node::local_node::NodeError),
#[error("message corruption")]
Corruption(#[source] mesh_protobuf::Error),
}
#[derive(Debug, Error)]
pub enum TryRecvError {
#[error("channel empty")]
Empty,
#[error("channel closed")]
Closed,
#[error("channel failure")]
Error(#[from] ChannelError),
}
#[derive(Debug, Error)]
pub enum RecvError {
#[error("channel closed")]
Closed,
#[error("channel failure")]
Error(#[from] ChannelError),
}