• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use crate::{size_hint, Arbitrary, Error, MaxRecursionReached, Unstructured};
2 
3 impl<'a, T, E> Arbitrary<'a> for Result<T, E>
4 where
5     T: Arbitrary<'a>,
6     E: Arbitrary<'a>,
7 {
arbitrary(u: &mut Unstructured<'a>) -> Result<Self, Error>8     fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self, Error> {
9         Ok(if <bool as Arbitrary<'a>>::arbitrary(u)? {
10             Ok(<T as Arbitrary>::arbitrary(u)?)
11         } else {
12             Err(<E as Arbitrary>::arbitrary(u)?)
13         })
14     }
15 
16     #[inline]
size_hint(depth: usize) -> (usize, Option<usize>)17     fn size_hint(depth: usize) -> (usize, Option<usize>) {
18         Self::try_size_hint(depth).unwrap_or_default()
19     }
20 
21     #[inline]
try_size_hint(depth: usize) -> Result<(usize, Option<usize>), MaxRecursionReached>22     fn try_size_hint(depth: usize) -> Result<(usize, Option<usize>), MaxRecursionReached> {
23         Ok(size_hint::and(
24             <bool as Arbitrary>::size_hint(depth),
25             size_hint::or(
26                 <T as Arbitrary>::try_size_hint(depth)?,
27                 <E as Arbitrary>::try_size_hint(depth)?,
28             ),
29         ))
30     }
31 }
32