| 1 |
use { |
| 2 |
crate::{size_hint, Arbitrary, Result, Unstructured}, |
| 3 |
std::sync::Arc, |
| 4 |
}; |
| 5 |
|
| 6 |
impl<'a, A> Arbitrary<'a> for Arc<A> |
| 7 |
where |
| 8 |
A: Arbitrary<'a>, |
| 9 |
{ |
| 10 |
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { |
| 11 |
Arbitrary::arbitrary(u).map(Self::new) |
| 12 |
} |
| 13 |
|
| 14 |
#[inline] |
| 15 |
fn size_hint(depth: usize) -> (usize, Option<usize>) { |
| 16 |
Self::try_size_hint(depth).unwrap_or_default() |
| 17 |
} |
| 18 |
|
| 19 |
#[inline] |
| 20 |
fn try_size_hint(depth: usize) -> Result<(usize, Option<usize>), crate::MaxRecursionReached> { |
| 21 |
size_hint::try_recursion_guard(depth, <A as Arbitrary>::try_size_hint) |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
impl<'a, A> Arbitrary<'a> for Arc<[A]> |
| 26 |
where |
| 27 |
A: Arbitrary<'a>, |
| 28 |
{ |
| 29 |
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { |
| 30 |
u.arbitrary_iter()?.collect() |
| 31 |
} |
| 32 |
|
| 33 |
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> { |
| 34 |
u.arbitrary_take_rest_iter()?.collect() |
| 35 |
} |
| 36 |
|
| 37 |
#[inline] |
| 38 |
fn size_hint(_depth: usize) -> (usize, Option<usize>) { |
| 39 |
(0, None) |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
impl<'a> Arbitrary<'a> for Arc<str> { |
| 44 |
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { |
| 45 |
<&str as Arbitrary>::arbitrary(u).map(Into::into) |
| 46 |
} |
| 47 |
|
| 48 |
#[inline] |
| 49 |
fn size_hint(depth: usize) -> (usize, Option<usize>) { |
| 50 |
<&str as Arbitrary>::size_hint(depth) |
| 51 |
} |
| 52 |
} |