1use crate::{generate::Generate, primitive::Constant, shrink::Shrink, state::State};
2
3#[derive(Clone, Debug)]
4pub struct Keep<T: ?Sized>(pub(crate) T);
5
6impl<G: Generate + ?Sized> Generate for Keep<G> {
7 type Item = G::Item;
8 type Shrink = Keep<G::Shrink>;
9
10 const CARDINALITY: Option<u128> = G::CARDINALITY;
11
12 fn generate(&self, state: &mut State) -> Self::Shrink {
13 Keep(self.0.generate(state))
14 }
15
16 fn cardinality(&self) -> Option<u128> {
17 self.0.cardinality()
18 }
19}
20
21impl<S: Shrink> Shrink for Keep<S> {
22 type Item = S::Item;
23
24 fn item(&self) -> Self::Item {
25 self.0.item()
26 }
27
28 fn shrink(&mut self) -> Option<Self> {
29 None
30 }
31}
32
33impl<C: Constant> Constant for Keep<C> {
34 const VALUE: Self = Self(C::VALUE);
35}