estring/src/error.rs

35 lines
760 B
Rust
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use crate::core::EString;
/// The error type for operations interacting with ``EString``s fragments.
#[derive(Debug, PartialEq, Eq)]
pub struct Error(pub EString, pub Reason);
/// The reason for the failure to parse.
#[derive(Debug, PartialEq, Eq)]
pub enum Reason {
/// Cannot split fragment
Split,
/// Cannot parse fragment
Parse,
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
r#"Failed to parse "{:?}" with reason {:?}"#,
self.0, self.1
)
}
}
impl std::error::Error for Error {}
impl std::ops::Deref for Error {
type Target = String;
fn deref(&self) -> &Self::Target {
&self.0
}
}