noodles_htsget/
lib.rs

1//! **noodles-htsget** is an htsget 1.3 client.
2
3pub(crate) mod chunks;
4mod client;
5mod format;
6pub mod reads;
7pub(crate) mod request;
8pub mod response;
9pub mod variants;
10
11pub use self::{client::Client, format::Format, response::Response};
12
13use std::{error, fmt};
14
15type Result<T> = std::result::Result<T, Error>;
16
17/// An error returned when anything fails to process.
18#[derive(Debug)]
19pub enum Error {
20    /// An input is invalid.
21    Input,
22    /// The URL failed to parse.
23    Url(url::ParseError),
24    /// The request failed to process.
25    Request(reqwest::Error),
26    /// The response is an error.
27    Response(response::Error),
28    /// The data failed to decode.
29    Decode(base64::DecodeError),
30    /// The data URL is invalid.
31    InvalidDataUrl,
32}
33
34impl error::Error for Error {
35    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
36        match self {
37            Self::Url(e) => Some(e),
38            Self::Request(e) => Some(e),
39            Self::Response(e) => Some(e),
40            Self::Decode(e) => Some(e),
41            _ => None,
42        }
43    }
44}
45
46impl fmt::Display for Error {
47    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48        match self {
49            Self::Input => f.write_str("invalid input"),
50            Self::Url(_) => f.write_str("URL error"),
51            Self::Request(_) => f.write_str("request error"),
52            Self::Response(_) => f.write_str("response error"),
53            Self::Decode(_) => f.write_str("decode error"),
54            Self::InvalidDataUrl => f.write_str("invalid data URL"),
55        }
56    }
57}