#[macro_export]
macro_rules! val {
($($a:ident $(:$t:ty)? = $b:expr);* $(;)?) => {
$(let $a $(:$t)? = $b;)*
};
}
#[macro_export]
macro_rules! var {
($($a:ident $(:$t:ty)? = $b:expr);* $(;)?) => {
$(let mut $a $(:$t)? = $b;)*
};
}
#[macro_export]
macro_rules! s {
($($a:ident = $b:expr);* $(;)?) => {
$(let $a = ext::no_std::functions::fun::s($b);)*
};
}
#[macro_export]
macro_rules! sm {
($($a:ident = $b:expr);* $(;)?) => {
$(let mut $a = ext::no_std::functions::fun::s($b);)*
};
}
#[macro_export]
macro_rules! swap {
($($a:ident, $b:ident);* $(;)?) => {
$(let ($b, $a) = ($a, $b);)*
};
}
#[macro_export]
macro_rules! swap_mut {
($($a:ident, $b:ident);* $(;)?) => {
$(let (mut $b, mut $a) = ($a, $b);)*
};
}
#[macro_export]
macro_rules! asserts {
($($a:expr);* $(;)?) => {
$(assert!($a);)*
};
}
#[macro_export]
macro_rules! assert_eqs {
($($a:expr, $b:expr);* $(;)?) => {
$(assert_eq!($a, $b);)*
};
}
#[macro_export]
macro_rules! assert_nes {
($($a:expr, $b:expr);* $(;)?) => {
$(assert_ne!($a, $b);)*
};
}
#[macro_export]
macro_rules! when {
($predicate:expr => $true:expr ; $false:expr) => {
if $predicate { $true } else { $false }
};
($($(let $a:ident $(:$t:ty)? =)? $predicate:expr => $true:expr ; $false:expr),* $(,)?) => {
$($(let $a $(:$t)? =)? if $predicate { $true } else { $false };)*
};
}
#[macro_export]
macro_rules! structs_default_decl {
($vis:vis struct $s_name:ident; $($tail:tt)*) => {$vis struct $s_name; structs_default_decl! { $($tail)* }};
($(#[$attr:meta])* $vis:vis struct $name:ident $(<$($generic:tt),*>)? {
$($field_vis:vis $field:ident: $type:ty = $val:expr),* $(,)?
}
$($tail:tt)*) => {
$(#[$attr])*
$vis struct $name $(<$($generic),*>)? {
$($field_vis $field: $type),*
}
impl $(<$($generic),*>)? Default for $name $(<$($generic),*>)? {
fn default() -> Self {
$name {
$($field: $val),*
}
}
}
structs_default_decl! {
$($tail)*
}
};
() => {}
}
#[macro_export]
macro_rules! structs_new_decl {
($vis:vis struct $s_name:ident; $($tail:tt)*) => {$vis struct $s_name; structs_new_decl! { $($tail)* }};
($(#[$attr:meta])* $vis:vis struct $s_name:ident $(<$($generic:tt),*>)? $(($($p_vis:vis $p_name:ident: $p_type:ty),* $(,)?))? $(where $($id:tt: $limit:tt),*)? {
$($field_vis:vis $field:ident: $type:ty = $val:expr),* $(,)?
}
$($tail:tt)*) => {
$(#[$attr])*
$vis struct $s_name $(<$($generic),*>)? $(where $($id: $limit),*)? {
$($($p_vis $p_name: $p_type,)*)?
$($field_vis $field: $type),*
}
impl $(<$($generic),*>)? $s_name $(<$($generic),*>)? $(where $($id: $limit),*)? {
fn new($($($p_name: $p_type),*)?) -> Self {
$s_name {
$($($p_name,)*)?
$($field: $val),*
}
}
}
structs_new_decl! {
$($tail)*
}
};
() => {}
}
#[macro_export]
macro_rules! structs_from_decl {
($vis:vis struct $s_name:ident; $($tail:tt)*) => {$vis struct $s_name; structs_from_decl! { $($tail)* }};
($vis:vis struct $s_name:ident {} $($tail:tt)*) => {$vis struct $s_name {} structs_from_decl! { $($tail)* }};
($(#[$attr:meta])* $vis:vis struct $name:ident $(<$($generic:tt),*>)? ($from:ident: $from_type:ty) $(where $($id:tt: $limit:tt),*)? {
$($field_vis:vis $field:ident: $type:ty = $val:expr),* $(,)?
}
$($tail:tt)*) => {
$(#[$attr])*
$vis struct $name $(<$($generic),*>)? $(where $($id: $limit),*)? {
$($field_vis $field: $type),*
}
impl $(<$($generic),*>)? From<$from_type> for $name $(<$($generic),*>)? $(where $($id: $limit),*)? {
fn from($from: $from_type) -> Self {
$name {
$($field: $val),*
}
}
}
structs_from_decl! {
$($tail)*
}
};
() => {}
}