macro_rules! log_error {
() => { ... };
($($t:tt)*) => { ... };
}Expand description
Creates a closure that error logs a formatted string and returns the closure’s argument.
The argument for the error_map! macro must be a format string and some parameters
(according to the format_args macro). The macro will then create a closure that just
returns its argument, but as a side effect will error log the string which was generated
from the macro arguments, appended with error.to_string().
The intended use for log_error! is as a closure argument for the Result::map_err method,
error logging a message as a side effect.
§Examples
use dsh_api::log_error;
fn save(path: PathBuf, data: &[u8]) -> Result<(), std::io::Error> {
write(&path, data)
.map_err(log_error!("writing {} failed, caused by ", path.display()))?;
Ok(())
}