use serde::de;
use std::fmt::{self, Display};
#[derive(Debug, Clone, Deserialize, PartialEq)]
pub struct ApiError {
text: String,
}
impl de::Error for ApiError {
fn custom<T: std::string::ToString>(msg: T) -> Self {
ApiError {
text: msg.to_string(),
}
}
}
impl Display for ApiError {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str(&self.to_string())
}
}
impl std::error::Error for ApiError {
fn description(&self) -> &str {
&self.text
}
}
impl ApiError {
pub fn new(text: impl Display) -> ApiError {
ApiError {
text: text.to_string(),
}
}
pub fn description(&self) -> &str {
&self.text
}
}