#[cfg(test)]
mod test;
mod builder;
mod client;
pub mod model;
pub use builder::ClientBuilder;
pub use client::MALClient;
use serde::{Deserialize, Serialize};
use std::error::Error;
use std::fmt::{Debug, Display};
#[derive(Serialize, Deserialize)]
pub struct MALError {
pub error: String,
pub message: Option<String>,
pub info: Option<String>,
}
impl Display for MALError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "lib_mal encountered an error: {}", self.error)
}
}
impl Debug for MALError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"error: {} message: {} info: {}",
self.error,
self.message.as_ref().unwrap_or(&"none".to_string()),
self.info.as_ref().unwrap_or(&"none".to_string())
)
}
}
impl Error for MALError {}
impl MALError {
pub fn new(msg: &str, error: &str, info: impl Into<Option<String>>) -> Self {
MALError {
error: error.to_owned(),
message: Some(msg.to_owned()),
info: info.into(),
}
}
}
pub mod prelude {
pub use crate::builder::ClientBuilder;
pub use crate::client::MALClient;
pub use crate::model::*;
}