Skip to main content

async_flow/error/
error.rs

1// This is free and unencumbered software released into the public domain.
2
3use super::{RecvError, SendError, TryRecvError, TrySendError};
4use alloc::boxed::Box;
5use thiserror::Error;
6
7pub type Result<T = (), E = Error> = core::result::Result<T, E>;
8
9#[derive(Debug, Error)]
10pub enum Error {
11    #[error("{0}")]
12    Recv(#[from] RecvError),
13
14    #[error("{0}")]
15    TryRecv(#[from] TryRecvError),
16
17    #[error("{0}")]
18    Send(#[from] SendError),
19
20    #[error("{0}")]
21    TrySend(#[from] TrySendError),
22
23    #[cfg(feature = "tokio")]
24    #[error("{0}")]
25    Join(#[from] tokio::task::JoinError),
26
27    #[cfg(feature = "std")]
28    #[error("{0}")]
29    Stdio(#[from] std::io::Error),
30
31    #[error("{0}")]
32    Other(#[from] Box<dyn core::error::Error + Send + Sync>),
33}
34
35#[cfg(feature = "serde")]
36impl From<serde_json::Error> for Error {
37    fn from(value: serde_json::Error) -> Self {
38        Error::Other(Box::new(value))
39    }
40}