Skip to content

Commit

Permalink
extract macros
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesvollmer committed Jul 2, 2024
1 parent 9ea54ca commit 56183d0
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/meta/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,23 +767,31 @@ impl Header {
// used to type-check local variables. only requried because you cannot do `let i: impl Iterator<> = ...`
#[inline] fn expect_is_iter<'s, T: Iterator<Item=(&'s TextSlice, AttributeValue)>>(val: T) -> T { val }

macro_rules! iter_all {
( $( $value:expr ),* ) => {
empty() $( .chain( $value ) )*
};
}

macro_rules! iter_values {
( $( $value:expr ),* ) => {
empty() $( .chain(once( $value )) )*
};
}

macro_rules! required_attributes {
( $($name: ident : $variant: ident = $value: expr),* ) => {
expect_is_iter(empty()
$(
.chain(once(required($name, $variant, $value))) // TODO without clone
)*
)
expect_is_iter(iter_values!(
$( required($name, $variant, $value) ),*
))
};
}

macro_rules! optional_attributes {
( $($name: ident : $variant: ident = $value: expr),* ) => {
expect_is_iter(empty()
$(
.chain(optional($name, $variant, $value)) // TODO without clone
)*
)
expect_is_iter(iter_all!(
$( optional($name, $variant, $value) ),*
))
};
}

Expand Down

0 comments on commit 56183d0

Please sign in to comment.