• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use {
2     crate::{size_hint, Arbitrary, Result, Unstructured},
3     std::borrow::{Cow, ToOwned},
4 };
5 
6 impl<'a, A> Arbitrary<'a> for Cow<'a, A>
7 where
8     A: ToOwned + ?Sized + 'a,
9     <A as ToOwned>::Owned: Arbitrary<'a>,
10 {
arbitrary(u: &mut Unstructured<'a>) -> Result<Self>11     fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
12         Arbitrary::arbitrary(u).map(Cow::Owned)
13     }
14 
15     #[inline]
size_hint(depth: usize) -> (usize, Option<usize>)16     fn size_hint(depth: usize) -> (usize, Option<usize>) {
17         Self::try_size_hint(depth).unwrap_or_default()
18     }
19 
20     #[inline]
try_size_hint(depth: usize) -> Result<(usize, Option<usize>), crate::MaxRecursionReached>21     fn try_size_hint(depth: usize) -> Result<(usize, Option<usize>), crate::MaxRecursionReached> {
22         size_hint::try_recursion_guard(depth, |depth| {
23             <<A as ToOwned>::Owned as Arbitrary>::try_size_hint(depth)
24         })
25     }
26 }
27