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 { arbitrary(u: &mut Unstructured<'a>) -> Result<Self>10 fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { 11 Arbitrary::arbitrary(u).map(Self::new) 12 } 13 14 #[inline] size_hint(depth: usize) -> (usize, Option<usize>)15 fn size_hint(depth: usize) -> (usize, Option<usize>) { 16 Self::try_size_hint(depth).unwrap_or_default() 17 } 18 19 #[inline] try_size_hint(depth: usize) -> Result<(usize, Option<usize>), crate::MaxRecursionReached>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 { arbitrary(u: &mut Unstructured<'a>) -> Result<Self>29 fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { 30 u.arbitrary_iter()?.collect() 31 } 32 arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self>33 fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> { 34 u.arbitrary_take_rest_iter()?.collect() 35 } 36 37 #[inline] size_hint(_depth: usize) -> (usize, Option<usize>)38 fn size_hint(_depth: usize) -> (usize, Option<usize>) { 39 (0, None) 40 } 41 } 42 43 impl<'a> Arbitrary<'a> for Arc<str> { arbitrary(u: &mut Unstructured<'a>) -> Result<Self>44 fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { 45 <&str as Arbitrary>::arbitrary(u).map(Into::into) 46 } 47 48 #[inline] size_hint(depth: usize) -> (usize, Option<usize>)49 fn size_hint(depth: usize) -> (usize, Option<usize>) { 50 <&str as Arbitrary>::size_hint(depth) 51 } 52 } 53