document try_log!() macro

master
rasul 5 years ago
parent 8896e4968a
commit fe317c0ca5

@ -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<T, Box<dyn Error>>`
/// * `$($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_export]
macro_rules! try_log { macro_rules! try_log {
($e:expr, $($arg:tt)*) => { ($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_export]
macro_rules! try_print { macro_rules! try_print {
($e:expr, $($arg:tt)*) => { ($e:expr, $($arg:tt)*) => {

Loading…
Cancel
Save