arbitrary/foreign/core/
cell.rs

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