1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
/// Abbr. of `let`
///
/// # Examples
///
/// ```
/// use aoko::l;
///
/// l!(foo = 233; bar = 666);
/// assert_eq!((233, 666), (foo, bar));
/// ```
#[macro_export]
macro_rules! l {
($($a:ident = $b:expr);*) => {
$(let $a = $b;)*
};
}
/// Abbr. of `let mut`
///
/// # Examples
///
/// ```
/// use aoko::lm;
///
/// lm!(foo = 233; bar = 1024);
/// foo = 666; bar = 2048;
/// assert_eq!((666, 2048), (foo, bar));
/// ```
#[macro_export]
macro_rules! lm {
($($a:ident = $b:expr);*) => {
$(let mut $a = $b;)*
};
}
/// Swaps two variables' value.
///
/// # Principles
///
/// Shadowing by two immutable variables.
///
/// # Examples
///
/// ```
/// use aoko::swap;
///
/// let (a, b, c, d) = (1, 2, 3, 4);
/// swap!(a, b; c, d);
/// assert_eq!((a, b, c, d), (2, 1, 4, 3));
/// ```
#[macro_export]
macro_rules! swap {
($($a:ident, $b:ident);*) => {
$(let ($b, $a) = ($a, $b);)*
};
}
/// Swaps two variables' value.
///
/// # Principles
///
/// Shadowing by two mutable variables.
///
/// # Examples
///
/// ```
/// use aoko::swap_mut;
///
/// let (a, b, c, d) = (1, 2, 3, 4);
/// swap_mut!(a, b; c, d);
/// assert_eq!((a, b, c, d), (2, 1, 4, 3));
///
/// a = 10; b = 20; c = 30; d = 40;
/// assert_eq!((a, b, c, d), (10, 20, 30, 40));
/// ```
#[macro_export]
macro_rules! swap_mut {
($($a:ident, $b:ident);*) => {
$(let (mut $b, mut $a) = ($a, $b);)*
};
}