From d8e3b21143cc8242f48a2e476acd2c73105bafdf Mon Sep 17 00:00:00 2001 From: rasul Date: Sun, 5 Apr 2020 14:57:17 -0500 Subject: [PATCH] document try_option_send_error!() macro --- src/macros.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 8ee092a..9677179 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -146,7 +146,30 @@ macro_rules! try_send { }; } -/// Unwrap a `Option`, send a message if it's None. +/// Unarap an `Option` and return a custom message for the client if it is None. +/// +/// # Arguments +/// +/// * `$i:ident` : `mio::Token` client identifier +/// * `$e:expr` : Expression to evaluate, must return `Option` +/// * `$($arg:tt)*` : Format string and parameters (like `println!()`) +/// +/// # Example +/// +/// ``` +/// use mio::Token; +/// use rude::queue::SendQueue; +/// use rude::option_send; +/// +/// fn check_file() -> SendQueue { +/// let token = Token(12); +/// let option = Some(4); +/// let send = option_send!(token, option, "Option unwrapped to None"); +/// SendQueue::ok(token) +/// } +/// +/// # assert_eq!(check_file().0[0].1, SendQueue::ok(Token(12)).0[0].1); +/// ``` #[macro_export] macro_rules! option_send { ($i:ident, $e:expr, $($arg:tt)*) => { @@ -161,7 +184,31 @@ macro_rules! option_send { }; } -/// Unwrap a `Result, E>`, log message if it's error or none +/// Unwrap a `Result, E>` and for Err or None, log a message and send +/// a generic error message to the client. +/// +/// # Arguments +/// +/// * `$i:ident` : `mio::Token` client identifier +/// * `$e:expr` : Expression to evaluate, must return `Result>` +/// +/// # Example +/// +/// ``` +/// use std::error::Error; +/// use mio::Token; +/// use rude::queue::SendQueue; +/// use rude::try_option_send_error; +/// +/// fn tor() -> SendQueue { +/// let token = Token(12); +/// let tor: Result, Box> = Ok(Some(42)); +/// let file = try_option_send_error!(token, tor); +/// SendQueue::ok(token) +/// } +/// +/// # assert_eq!(tor().0[0].1, SendQueue::ok(Token(12)).0[0].1); +/// ``` #[macro_export] macro_rules! try_option_send_error { ($i:ident, $e:expr) => {