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
28
29
30
31
32
33
34
35
36
37
38
use crate::{
    generate::{Generate, State},
    shrink::Shrink,
    IntoShrink,
};

#[derive(Clone, Debug)]
pub struct Keep<T: ?Sized>(pub T);

impl<G: Generate + ?Sized> Generate for Keep<G> {
    type Item = G::Item;
    type Shrink = Keep<G::Shrink>;

    fn generate(&self, state: &mut State) -> Self::Shrink {
        Keep(self.0.generate(state))
    }
}

impl<S: IntoShrink> IntoShrink for Keep<S> {
    type Item = S::Item;
    type Shrink = Keep<S::Shrink>;

    fn shrinker(&self, item: Self::Item) -> Option<Self::Shrink> {
        Some(Keep(self.0.shrinker(item)?))
    }
}

impl<S: Shrink> Shrink for Keep<S> {
    type Item = S::Item;

    fn item(&self) -> Self::Item {
        self.0.item()
    }

    fn shrink(&mut self) -> Option<Self> {
        None
    }
}