mod error;
pub trait LoggableError<T>: Sized {
#[track_caller]
fn print_error<F: Fn(&str)>(self, fun: F) -> Self;
#[cfg(not(feature = "log"))]
fn to_log(self) -> Self;
#[cfg(feature = "log")]
#[track_caller]
fn to_log(self) -> Self {
let caller = std::panic::Location::caller();
self.print_error(|msg| {
log::logger().log(
&log::Record::builder()
.level(log::Level::Error)
.args(format_args!("{}", msg))
.file(Some(caller.file()))
.line(Some(caller.line()))
.module_path(None)
.build(),
);
})
}
fn to_stderr(self) -> Self {
self.print_error(|msg| eprintln!("{}", msg))
}
fn to_stdout(self) -> Self {
self.print_error(|msg| println!("{}", msg))
}
}