rs-pixel 0.2.0

A complete, rate-limiting, asynchronous Rust implementation of the Hypixel Public API with extensive SkyBlock support
Documentation
use serde_json;
use std::fmt;

#[derive(Debug)]
pub enum Error {
    Client(surf::Error),
    Parse(serde_json::Error),
    Status(u16, String),
    RateLimit(i64),
    Unknown(String),
    UnknownResource,
}

impl std::error::Error for Error {}

impl From<surf::Error> for Error {
    fn from(e: surf::Error) -> Self {
        Error::Client(e)
    }
}

impl From<serde_json::Error> for Error {
    fn from(e: serde_json::Error) -> Self {
        Error::Parse(e)
    }
}

impl From<String> for Error {
    fn from(e: String) -> Self {
        Error::Unknown(e)
    }
}

impl From<(surf::StatusCode, String)> for Error {
    fn from(e: (surf::StatusCode, String)) -> Self {
        Error::Status(e.0.into(), e.1)
    }
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match *self {
            Error::Client(ref err) => err.fmt(f),
            Error::Parse(ref err) => err.fmt(f),
            Error::Unknown(ref err) => err.fmt(f),
            Error::Status(ref code, ref err) => write!(f, "{code} {err}"),
            Error::RateLimit(ref time_till_reset) => write!(
                f,
                "Reached the rate limit; {time_till_reset} seconds till reset"
            ),
            Error::UnknownResource => write!(f, "Unknown resource provided"),
        }
    }
}