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
/// Abbr. of `let mut`
///
/// # Examples
///
/// ```
/// use aoko::lm;
///
/// lm!(foo = 1024);
/// foo = 2048;
/// assert_eq!(2048, foo);
/// ```
#[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 (foo, bar) = ('a', 'b');
/// swap!(foo, bar);
/// assert_eq!(('b', 'a'), (foo, bar));
/// ```
#[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 (foo, bar) = ('a', 'b');
/// swap_mut!(foo, bar);
/// assert_eq!(('b', 'a'), (foo, bar));
///
/// foo = 'x';
/// bar = 'y';
/// assert_eq!(('x', 'y'), (foo, bar));
/// ```
#[macro_export]
macro_rules! swap_mut {
($a:ident, $b:ident) => {
let (mut $b, mut $a) = ($a, $b);
};
}