macro_rules! struct_iter {
(
$( #[ $type_attr:meta ] )*
$vis:vis struct $struct_name:ident {
$(
$( #[ $field_attr:meta ] )*
$field_vis:vis $field:ident: $field_type:ty
),* $(,)?
}
) => { ... };
}
Expand description
Implements the iter
function, which returns an iterator over all possible
combinations of the struct’s fields, assuming each field’s type implements
the iter
function itself.
§Example
enum_iter! {
#[derive(Eq, PartialEq, Debug, Clone)]
enum Species {
BlueDragon,
RedDragon,
}
}
enum_iter! {
#[derive(Eq, PartialEq, Debug, Clone)]
enum BodyType {
Male,
Female,
}
}
struct_iter! {
#[derive(Eq, PartialEq, Debug)]
struct Body {
species: Species,
body_type: BodyType,
}
}
let results: Vec<_> = Body::iter().collect();
assert_eq!(results, vec![
Body {
species: Species::BlueDragon,
body_type: BodyType::Male
},
Body {
species: Species::BlueDragon,
body_type: BodyType::Female
},
Body {
species: Species::RedDragon,
body_type: BodyType::Male
},
Body {
species: Species::RedDragon,
body_type: BodyType::Female
},
])