document try_print!() macro

master
rasul 5 years ago
parent fe317c0ca5
commit 632d5dfcbe

@ -33,8 +33,26 @@ macro_rules! try_log {
};
}
/// Unwrap a Result, if it's Err then print the error and the provided format
/// string and return.
/// Unwrap a Result. If it's Err then print the error and provided format string
/// and return.
///
/// # Arguments
///
/// * `$e:expr` : Expression to evaluate, must return `Result<T, Box<dyn Error>>`
/// * `$($arg:tt)*` : Format string and parameters (like `println!()`)
///
/// # Example
///
/// ```
/// use std::fs::File;
/// use rude::result::RudeResult;
/// use rude::try_print;
///
/// fn main() -> RudeResult<()> {
/// let readme = try_print!(File::open(file!()), "Unable to open {}", file!());
/// Ok(())
/// }
/// ```
#[macro_export]
macro_rules! try_print {
($e:expr, $($arg:tt)*) => {

Loading…
Cancel
Save