mparsed/src/error.rs
2020-06-13 09:24:58 +02:00

41 lines
780 B
Rust

use pest;
use serde::de;
use std::fmt::{self, Display};
use crate::Rule;
pub type MpdResult<T> = std::result::Result<T, Error>;
#[derive(Clone, Debug, PartialEq)]
pub struct Error {
pub message: String,
}
impl From<pest::error::Error<Rule>> for Error {
fn from(err: pest::error::Error<Rule>) -> Self {
Error {
message: err.to_string(),
}
}
}
impl de::Error for Error {
fn custom<T: Display>(msg: T) -> Self {
Error {
message: msg.to_string(),
}
}
}
impl Display for Error {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(&self.message)
}
}
impl std::error::Error for Error {
fn description(&self) -> &str {
&self.message
}
}