1 use crate::{size_hint, Arbitrary, MaxRecursionReached, Result, Unstructured}; 2 3 macro_rules! arbitrary_tuple { 4 () => {}; 5 ($last: ident $($xs: ident)*) => { 6 arbitrary_tuple!($($xs)*); 7 8 impl<'a, $($xs,)* $last> Arbitrary<'a> for ($($xs,)* $last,) 9 where 10 $($xs: Arbitrary<'a>,)* 11 $last: Arbitrary<'a>, 12 { 13 fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { 14 Ok(($($xs::arbitrary(u)?,)* Arbitrary::arbitrary(u)?,)) 15 } 16 17 #[allow(unused_mut, non_snake_case)] 18 fn arbitrary_take_rest(mut u: Unstructured<'a>) -> Result<Self> { 19 $(let $xs = $xs::arbitrary(&mut u)?;)* 20 let $last = $last::arbitrary_take_rest(u)?; 21 Ok(($($xs,)* $last,)) 22 } 23 24 #[inline] 25 fn size_hint(depth: usize) -> (usize, Option<usize>) { 26 Self::try_size_hint(depth).unwrap_or_default() 27 } 28 #[inline] 29 fn try_size_hint(depth: usize) -> Result<(usize, Option<usize>), MaxRecursionReached> { 30 Ok(size_hint::and_all(&[ 31 <$last as Arbitrary>::try_size_hint(depth)?, 32 $( <$xs as Arbitrary>::try_size_hint(depth)?),* 33 ])) 34 } 35 } 36 }; 37 } 38 arbitrary_tuple!(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z); 39