|
|
|
@ -146,7 +146,30 @@ macro_rules! try_send {
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Unwrap a `Option<T>`, 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<T>`
|
|
|
|
|
/// * `$($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<Option<T>, E>`, log message if it's error or none
|
|
|
|
|
/// Unwrap a `Result<Option<T>, 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<T, Box<dyn Error>>`
|
|
|
|
|
///
|
|
|
|
|
/// # 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<Option<usize>, Box<dyn Error>> = 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) => {
|
|
|
|
|