bolero_generator/driver/
options.rs

1use core::time::Duration;
2
3#[derive(Clone, Debug, Default)]
4pub struct Options {
5    shrink_time: Option<Duration>,
6    max_depth: Option<usize>,
7    max_len: Option<usize>,
8    exhaustive: bool,
9}
10
11impl Options {
12    pub const DEFAULT_MAX_DEPTH: usize = 5;
13    pub const DEFAULT_MAX_LEN: usize = 4096;
14    pub const DEFAULT_SHRINK_TIME: Duration = Duration::from_secs(1);
15
16    pub fn with_shrink_time(mut self, shrink_time: Duration) -> Self {
17        self.shrink_time = Some(shrink_time);
18        self
19    }
20
21    pub fn with_max_depth(mut self, max_depth: usize) -> Self {
22        self.max_depth = Some(max_depth);
23        self
24    }
25
26    pub fn with_max_len(mut self, max_len: usize) -> Self {
27        self.max_len = Some(max_len);
28        self
29    }
30
31    pub fn with_exhaustive(mut self, exhaustive: bool) -> Self {
32        self.exhaustive = exhaustive;
33        self
34    }
35
36    pub fn set_exhaustive(&mut self, exhaustive: bool) -> &mut Self {
37        self.exhaustive = exhaustive;
38        self
39    }
40
41    pub fn set_shrink_time(&mut self, shrink_time: Duration) -> &mut Self {
42        self.shrink_time = Some(shrink_time);
43        self
44    }
45
46    pub fn set_max_depth(&mut self, max_depth: usize) -> &mut Self {
47        self.max_depth = Some(max_depth);
48        self
49    }
50
51    pub fn set_max_len(&mut self, max_len: usize) -> &mut Self {
52        self.max_len = Some(max_len);
53        self
54    }
55
56    #[inline]
57    pub fn exhaustive(&self) -> bool {
58        self.exhaustive
59    }
60
61    #[inline]
62    pub fn max_depth(&self) -> Option<usize> {
63        self.max_depth
64    }
65
66    #[inline]
67    pub fn max_len(&self) -> Option<usize> {
68        self.max_len
69    }
70
71    #[inline]
72    pub fn shrink_time(&self) -> Option<Duration> {
73        self.shrink_time
74    }
75
76    #[inline]
77    pub fn max_depth_or_default(&self) -> usize {
78        self.max_depth.unwrap_or(Self::DEFAULT_MAX_DEPTH)
79    }
80
81    #[inline]
82    pub fn max_len_or_default(&self) -> usize {
83        self.max_len.unwrap_or(Self::DEFAULT_MAX_LEN)
84    }
85
86    #[inline]
87    pub fn shrink_time_or_default(&self) -> Duration {
88        self.shrink_time.unwrap_or(Self::DEFAULT_SHRINK_TIME)
89    }
90
91    #[inline]
92    pub fn merge_from(&mut self, other: &Self) {
93        macro_rules! merge {
94            ($name:ident) => {
95                if let Some($name) = other.$name {
96                    self.$name = Some($name);
97                }
98            };
99        }
100
101        merge!(max_depth);
102        merge!(max_len);
103        merge!(shrink_time);
104    }
105}