mparsed/src/error.rs

36 lines
648 B
Rust
Raw Permalink Normal View History

2020-06-13 09:18:47 +02:00
use serde::de;
use std::fmt::{self, Display};
pub type MpdResult<T> = std::result::Result<T, Error>;
#[derive(Clone, Debug, PartialEq)]
pub struct Error {
pub message: String,
2020-06-13 09:18:47 +02:00
}
2020-06-20 22:08:33 +02:00
impl Error {
pub fn from_str(message: &str) -> Self {
Error {
message: message.to_string(),
2020-06-20 22:08:33 +02:00
}
}
2020-06-20 22:08:33 +02:00
}
2020-06-13 09:18:47 +02:00
impl de::Error for Error {
fn custom<T: Display>(msg: T) -> Self {
Error { message: msg.to_string() }
}
2020-06-13 09:18:47 +02:00
}
impl Display for Error {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(&self.message)
}
2020-06-13 09:18:47 +02:00
}
impl std::error::Error for Error {
fn description(&self) -> &str {
&self.message
}
2020-06-13 09:18:47 +02:00
}