1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use crate::{SmartString, SmartStringMode};
use alloc::{
    boxed::Box,
    string::{String, ToString},
};
use arbitrary::{Arbitrary, Result, Unstructured};

impl<Mode: SmartStringMode> Arbitrary for SmartString<Mode>
where
    Mode: 'static,
{
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
        String::arbitrary(u).map(Self::from)
    }

    fn arbitrary_take_rest(u: Unstructured<'_>) -> Result<Self> {
        String::arbitrary_take_rest(u).map(Self::from)
    }

    fn size_hint(depth: usize) -> (usize, Option<usize>) {
        String::size_hint(depth)
    }

    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
        Box::new(self.to_string().shrink().map(Self::from))
    }
}