From ab2522249e4df582c24be26f3f6e940d9cf0d8b8 Mon Sep 17 00:00:00 2001 From: rasul Date: Sun, 5 Apr 2020 13:27:44 -0500 Subject: [PATCH] document the try_send!() macro --- src/macros.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/macros.rs b/src/macros.rs index 5cccbc5..8ee092a 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -108,7 +108,30 @@ macro_rules! try_send_error { }; } -/// Unwrap a `Result`, send a message if it's E. +/// Unwrap a `Result` and return a custom message to send to the client for Err. +/// +/// # Arguments +/// +/// * `$i:ident` : `mio::Token` client identifier +/// * `$e:expr` : Expression to evaluate, must return `Result>` +/// * `$($arg:tt)*` : Format string and parameters (like `println!()`) +/// +/// # Example +/// +/// ``` +/// use std::fs::File; +/// use mio::Token; +/// use rude::queue::SendQueue; +/// use rude::try_send; +/// +/// fn check_file() -> SendQueue { +/// let token = Token(12); +/// let file = try_send!(token, File::open(file!()), "Unable to open {}", file!()); +/// SendQueue::ok(token) +/// } +/// +/// # assert_eq!(check_file().0[0].1, SendQueue::ok(Token(12)).0[0].1); +/// ``` #[macro_export] macro_rules! try_send { ($i:ident, $e:expr, $($arg:tt)*) => {