async_curl/
error.rs

1use std::fmt::Debug;
2
3use curl::easy::Handler;
4use tokio::sync::{mpsc::error::SendError, oneshot::error::RecvError};
5
6use crate::actor;
7
8/// This the enum of Errors for this crate.
9#[derive(Debug)]
10pub enum Error<H>
11where
12    H: Handler + Debug + Send + 'static,
13{
14    Curl(curl::Error),
15    Multi(curl::MultiError),
16    TokioRecv(RecvError),
17    TokioSend(SendError<actor::Request<H>>),
18}
19
20/// This convert RecvError to our customized
21/// Error enum for ease of management of
22/// different errors from 3rd party crates.
23impl<H> From<RecvError> for Error<H>
24where
25    H: Handler + Debug + Send + 'static,
26{
27    fn from(err: RecvError) -> Self {
28        Error::TokioRecv(err)
29    }
30}
31
32/// This convert SendError to our customized
33/// Error enum for ease of management of
34/// different errors from 3rd party crates.
35impl<H> From<SendError<actor::Request<H>>> for Error<H>
36where
37    H: Handler + Debug + Send + 'static,
38{
39    fn from(err: SendError<actor::Request<H>>) -> Self {
40        Error::TokioSend(err)
41    }
42}
43
44/// This convert curl::Error to our customized
45/// Error enum for ease of management of
46/// different errors from 3rd party crates.
47impl<H> From<curl::Error> for Error<H>
48where
49    H: Handler + Debug + Send + 'static,
50{
51    fn from(err: curl::Error) -> Self {
52        Error::Curl(err)
53    }
54}
55
56impl<H> std::fmt::Display for Error<H>
57where
58    H: Handler + Debug + Send + 'static,
59{
60    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
61        match self {
62            Error::Curl(err) => write!(f, "{}", err),
63            Error::Multi(err) => write!(f, "{}", err),
64            Error::TokioRecv(err) => write!(f, "{}", err),
65            Error::TokioSend(err) => write!(f, "{}", err),
66        }
67    }
68}
69
70impl<H> std::error::Error for Error<H> where H: Handler + Debug + Send + 'static {}