mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 03:36:42 +01:00
46 lines
1.2 KiB
Rust
46 lines
1.2 KiB
Rust
/// Static iteration helper.
|
|
#[macro_export] macro_rules! iterate {
|
|
($expr:expr => $arg: pat => $body:expr) => {
|
|
let mut iter = $expr;
|
|
while let Some(($arg, next)) = iter.next() {
|
|
$body;
|
|
iter = next;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Implement the const iterator pattern.
|
|
#[macro_export] macro_rules! const_iter {
|
|
($(<$l:lifetime>)?|$self:ident: $Struct:ty| => $Item:ty => $expr:expr) => {
|
|
impl$(<$l>)? Iterator for $Struct {
|
|
type Item = $Item;
|
|
fn next (&mut $self) -> Option<$Item> { $expr }
|
|
}
|
|
impl$(<$l>)? ConstIntoIter for $Struct {
|
|
type Kind = IsIteratorKind;
|
|
type Item = $Item;
|
|
type IntoIter = Self;
|
|
}
|
|
}
|
|
}
|
|
|
|
#[macro_export] macro_rules! get_value {
|
|
($state:expr => $token:expr) => {
|
|
if let Some(value) = $state.get(&$token.value) {
|
|
value
|
|
} else {
|
|
panic!("no value corresponding to {:?}", &$token.value);
|
|
}
|
|
}
|
|
}
|
|
|
|
#[macro_export] macro_rules! get_content {
|
|
($state:expr => $token:expr) => {
|
|
if let Some(content) = $state.get_content(&$token.value) {
|
|
content
|
|
} else {
|
|
panic!("no content corresponding to {:?}", &$token.value);
|
|
}
|
|
}
|
|
}
|
|
|