at_api_rs/
error.rs

1//! Error and result types which are passed by the library.
2
3use reqwest::Error as HTTPError;
4use std::error::Error as StdError;
5use std::fmt::Display;
6use std::result::Result as StdResult;
7
8/// The base Result type which is used in the library.
9pub type Result<T> = StdResult<T, Error>;
10
11/// An error which is returned from the library.
12#[derive(Debug)]
13#[non_exhaustive]
14pub enum Error {
15    /// An error occured while interacting with the AT API.
16    Request(Box<HTTPError>),
17}
18
19impl From<HTTPError> for Error {
20    fn from(e: HTTPError) -> Self {
21        Self::Request(Box::new(e))
22    }
23}
24
25impl StdError for Error {}
26
27impl Display for Error {
28    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
29        match self {
30            Error::Request(e) => write!(f, "HTTP request error: {}", e),
31        }
32    }
33}