#[derive(Debug, Default, PartialEq, Eq, Clone)]
pub struct Origin {
pub module_path: &'static str,
pub filename: &'static str,
pub line_nr: u32,
}
impl Origin {
pub fn new(module_path: &'static str, filename: &'static str, line_nr: u32) -> Self {
Origin {
module_path,
filename,
line_nr,
}
}
}
impl From<&Origin> for String {
fn from(origin: &Origin) -> Self {
format!(
"module=\"{}\", file=\"{}\", line={}",
origin.module_path, origin.filename, origin.line_nr
)
}
}
impl core::fmt::Display for Origin {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", String::from(self))
}
}
#[macro_export]
macro_rules! this_origin {
() => {
$crate::event::origin::Origin::new(module_path!(), file!(), line!())
};
}