From fe317c0ca547658aec321aee2ed0d347e2f65a18 Mon Sep 17 00:00:00 2001 From: rasul Date: Sun, 5 Apr 2020 12:39:10 -0500 Subject: [PATCH] document try_log!() macro --- src/macros.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 6735cb0..5cf3c4c 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,4 +1,24 @@ -/// Unwrap a Result, and log the error. +/// Unwrap a Result. If it's Err then log the error and provided format string +/// and return. +/// +/// # Arguments +/// +/// * `$e:expr` : Expression to evaluate, must return `Result>` +/// * `$($arg:tt)*` : Format string and parameters (like `println!()`) +/// +/// # Example +/// +/// ``` +/// use std::fs::File; +/// use rude::result::RudeResult; +/// use rude::try_log; +/// +/// fn main() -> RudeResult<()> { +/// let path = "README.md"; +/// let readme = try_log!(File::open(path), "Unable to open {}", path); +/// Ok(()) +/// } +/// ``` #[macro_export] macro_rules! try_log { ($e:expr, $($arg:tt)*) => { @@ -13,7 +33,8 @@ macro_rules! try_log { }; } -/// Unwrap a Result and print if it's an error +/// Unwrap a Result, if it's Err then print the error and the provided format +/// string and return. #[macro_export] macro_rules! try_print { ($e:expr, $($arg:tt)*) => {