veloren_common/util/
macros.rs

1/// A match that returns an option and has a wildcard pattern for `None`.
2///
3/// # Example
4/// ```
5/// use veloren_common::match_some;
6///
7/// let x = 5;
8/// let res = match_some!(x,
9///    1 => true,
10///    5 => false,
11/// );
12///
13/// assert_eq!(res, Some(false));
14/// ```
15#[macro_export]
16macro_rules! match_some {
17    ($expr:expr $(, $pat:pat => $ret_expr:expr)+ $(,)?) => {
18        match $expr {
19            $($pat => Some($ret_expr),)+
20            _ => None,
21        }
22    };
23}