1 use { 2 crate::{Arbitrary, MaxRecursionReached, Result, Unstructured}, 3 core::cell::{Cell, RefCell, UnsafeCell}, 4 }; 5 6 impl<'a, A> Arbitrary<'a> for Cell<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>), MaxRecursionReached>20 fn try_size_hint(depth: usize) -> Result<(usize, Option<usize>), MaxRecursionReached> { 21 <A as Arbitrary<'a>>::try_size_hint(depth) 22 } 23 } 24 25 impl<'a, A> Arbitrary<'a> for RefCell<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 Arbitrary::arbitrary(u).map(Self::new) 31 } 32 33 #[inline] size_hint(depth: usize) -> (usize, Option<usize>)34 fn size_hint(depth: usize) -> (usize, Option<usize>) { 35 Self::try_size_hint(depth).unwrap_or_default() 36 } 37 38 #[inline] try_size_hint(depth: usize) -> Result<(usize, Option<usize>), MaxRecursionReached>39 fn try_size_hint(depth: usize) -> Result<(usize, Option<usize>), MaxRecursionReached> { 40 <A as Arbitrary<'a>>::try_size_hint(depth) 41 } 42 } 43 44 impl<'a, A> Arbitrary<'a> for UnsafeCell<A> 45 where 46 A: Arbitrary<'a>, 47 { arbitrary(u: &mut Unstructured<'a>) -> Result<Self>48 fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { 49 Arbitrary::arbitrary(u).map(Self::new) 50 } 51 52 #[inline] size_hint(depth: usize) -> (usize, Option<usize>)53 fn size_hint(depth: usize) -> (usize, Option<usize>) { 54 Self::try_size_hint(depth).unwrap_or_default() 55 } 56 57 #[inline] try_size_hint(depth: usize) -> Result<(usize, Option<usize>), MaxRecursionReached>58 fn try_size_hint(depth: usize) -> Result<(usize, Option<usize>), MaxRecursionReached> { 59 <A as Arbitrary<'a>>::try_size_hint(depth) 60 } 61 } 62