nakamoto_net/
error.rs

1//! Peer-to-peer protocol errors.
2
3use std::fmt::Debug;
4use std::io;
5
6use crossbeam_channel as crossbeam;
7
8use thiserror::Error;
9
10/// An error occuring in peer-to-peer networking code.
11#[derive(Error, Debug)]
12pub enum Error {
13    /// An I/O error.
14    #[error("i/o error: {0}")]
15    Io(#[from] io::Error),
16
17    /// A channel send or receive error.
18    #[error("channel error: {0}")]
19    Channel(Box<dyn std::error::Error + Send + Sync + 'static>),
20}
21
22impl<T: Debug + Send + Sync + 'static> From<crossbeam::SendError<T>> for Error {
23    fn from(err: crossbeam::SendError<T>) -> Self {
24        Self::Channel(Box::new(err))
25    }
26}
27
28impl From<crossbeam::RecvError> for Error {
29    fn from(err: crossbeam::RecvError) -> Self {
30        Self::Channel(Box::new(err))
31    }
32}
33
34impl From<crossbeam::RecvTimeoutError> for Error {
35    fn from(err: crossbeam::RecvTimeoutError) -> Self {
36        Self::Channel(Box::new(err))
37    }
38}