use { crate::{size_hint, Arbitrary, Result, Unstructured}, std::boxed::Box, }; impl<'a, A> Arbitrary<'a> for Box where A: Arbitrary<'a>, { fn arbitrary(u: &mut Unstructured<'a>) -> Result { Arbitrary::arbitrary(u).map(Self::new) } #[inline] fn size_hint(depth: usize) -> (usize, Option) { Self::try_size_hint(depth).unwrap_or_default() } #[inline] fn try_size_hint(depth: usize) -> Result<(usize, Option), crate::MaxRecursionReached> { size_hint::try_recursion_guard(depth, ::try_size_hint) } } impl<'a, A> Arbitrary<'a> for Box<[A]> where A: Arbitrary<'a>, { fn arbitrary(u: &mut Unstructured<'a>) -> Result { u.arbitrary_iter()?.collect() } fn arbitrary_take_rest(u: Unstructured<'a>) -> Result { u.arbitrary_take_rest_iter()?.collect() } #[inline] fn size_hint(_depth: usize) -> (usize, Option) { (0, None) } } impl<'a> Arbitrary<'a> for Box { fn arbitrary(u: &mut Unstructured<'a>) -> Result { ::arbitrary(u).map(|x| x.into_boxed_str()) } #[inline] fn size_hint(depth: usize) -> (usize, Option) { ::size_hint(depth) } }