use gratte::{EnumDiscriminants, EnumIs};
use serde::{Deserialize, Serialize};
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug, thiserror::Error, EnumDiscriminants, EnumIs)]
#[non_exhaustive]
#[strum_discriminants(name(ErrorKind), derive(Serialize, Deserialize, EnumIs), non_exhaustive)]
pub enum Error {
#[cfg(feature = "http")]
#[error("http error: {0}")]
HttpGet(#[from] reqwest::Error),
#[error("session does not have access to this leaderboard")]
NoAccess,
}
impl Error {
#[cfg(feature = "http")]
pub fn is_http_get_and<P>(&self, predicate: P) -> bool
where
P: FnOnce(&reqwest::Error) -> bool,
{
match self {
Self::HttpGet(reqwest_err) => predicate(reqwest_err),
_ => false,
}
}
}
impl PartialEq<ErrorKind> for Error {
fn eq(&self, other: &ErrorKind) -> bool {
ErrorKind::from(self) == *other
}
}
impl PartialEq<Error> for ErrorKind {
fn eq(&self, other: &Error) -> bool {
*self == Self::from(other)
}
}