use core::fmt::{self, Display, Formatter};
#[macro_export]
#[doc(hidden)]
macro_rules! e {
($message:expr) => {{
$crate::error::Error::new($message, file!(), line!())
}};
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Error {
message: &'static str,
file: &'static str,
line: u32,
}
impl Error {
#[doc(hidden)]
pub const fn new(message: &'static str, file: &'static str, line: u32) -> Self {
Self { message, file, line }
}
pub const fn message(&self) -> &'static str {
self.message
}
pub const fn location(&self) -> (&'static str, u32) {
(self.file, self.line)
}
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "{} at {}:{}", self.message, self.file, self.line)
}
}
#[cfg(feature = "std")]
impl std::error::Error for Error {
}