document the try_send!() macro

master
rasul 5 years ago
parent 01bb588a05
commit ab2522249e

@ -108,7 +108,30 @@ macro_rules! try_send_error {
};
}
/// Unwrap a `Result<T, E>`, 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<T, Box<dyn Error>>`
/// * `$($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)*) => {

Loading…
Cancel
Save