macro_rules! path_tuple {
() => { ... };
($($expr:expr),* $(,)?) => { ... };
}
Expand description
For manually constructing a FieldPathSet
to access up to 64 fields.
§Example
This demonstrates how to construct a FieldPathSet
to access over 8 fields.
use structural::{ FieldPathSet, StructuralExt, path_tuple, ts };
let this = ('a', 'b', 3, 5, "foo", "bar", false, true, Some(8), Some(13));
// If you access up to 8 fields with `FieldPathSet::large(path_tuple!(....))`,
// then accessor methods return non-nested tuples.
{
let path8 = FieldPathSet::large(path_tuple!(
ts!(0), ts!(1), ts!(2), ts!(3), ts!(4), ts!(5), ts!(6), ts!(7)
));
assert_eq!(
this.fields(path8),
(&'a', &'b', &3, &5, &"foo", &"bar", &false, &true)
);
}
// If you access more than 8 fields with `FieldPathSet::large(path_tuple!(....))`,
// then accessor methods return nested tuples. 8 elements each.
{
let path10 = FieldPathSet::large(path_tuple!(
ts!(0), ts!(1), ts!(2), ts!(3), ts!(4), ts!(5), ts!(6), ts!(7),
ts!(8), ts!(9),
));
assert_eq!(
this.fields(path10),
(
(&'a', &'b', &3, &5, &"foo", &"bar", &false, &true),
(&Some(8), &Some(13))
),
);
assert_eq!(
this.cloned_fields(path10),
(
('a', 'b', 3, 5, "foo", "bar", false, true),
(Some(8), Some(13))
),
);
}
§Example
This demnstrates what the macro expands into:
use structural::path_tuple;
assert_eq!( path_tuple!(), () );
assert_eq!( path_tuple!(1), ((1,),) );
assert_eq!( path_tuple!(1, 2), ((1, 2),) );
assert_eq!(
path_tuple!(0, 1, 2, 3, 4, 5, 6, 7),
((0, 1, 2, 3, 4, 5, 6, 7),),
);
assert_eq!(
path_tuple!(0, 1, 2, 3, 4, 5, 6, 7, 8),
((0, 1, 2, 3, 4, 5, 6, 7), (8,)),
);
assert_eq!(
path_tuple!(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15),
(
(0, 1, 2, 3, 4, 5, 6, 7),
(8, 9, 10, 11, 12, 13, 14, 15),
),
);
assert_eq!(
path_tuple!(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16),
(
(0, 1, 2, 3, 4, 5, 6, 7),
(8, 9, 10, 11, 12, 13, 14, 15),
(16,),
)
);