arbitrary/foreign/alloc/
borrow.rs

1use {
2    crate::{size_hint, Arbitrary, Result, Unstructured},
3    std::borrow::{Cow, ToOwned},
4};
5
6impl<'a, A> Arbitrary<'a> for Cow<'a, A>
7where
8    A: ToOwned + ?Sized + 'a,
9    <A as ToOwned>::Owned: Arbitrary<'a>,
10{
11    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
12        Arbitrary::arbitrary(u).map(Cow::Owned)
13    }
14
15    #[inline]
16    fn size_hint(depth: usize) -> (usize, Option<usize>) {
17        Self::try_size_hint(depth).unwrap_or_default()
18    }
19
20    #[inline]
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}