#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::cmp::PartialEq;
use thiserror::Error;
#[derive(Error, Debug, Clone, Eq, PartialEq, Hash)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(rename_all = "camelCase")
)]
pub enum AsyncError {
#[error("{0}")]
Error(String),
#[error("Operation returned None!")]
None,
#[error("Task was cancelled!")]
Cancelled,
#[error("Deadline has elapsed!")]
Timeout,
}
impl AsyncError {
pub fn error(msg: impl Into<String>) -> Self {
AsyncError::Error(msg.into())
}
pub fn is_none(&self) -> bool {
matches!(self, AsyncError::None)
}
pub fn is_error(&self) -> bool {
matches!(self, AsyncError::Error { .. })
}
pub fn is_cancelled(&self) -> bool {
matches!(self, AsyncError::Cancelled)
}
pub fn is_timeout(&self) -> bool {
matches!(self, AsyncError::Timeout)
}
}