dcbor_pattern/reluctance.rs
1/// Reluctance for quantifiers.
2#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Default)]
3pub enum Reluctance {
4 /// Grabs as many repetitions as possible, then backtracks if the rest of
5 /// the pattern cannot match.
6 #[default]
7 Greedy,
8 /// Starts with as few repetitions as possible, adding more only if the rest
9 /// of the pattern cannot match.
10 Lazy,
11 /// Grabs as many repetitions as possible and never backtracks; if the rest
12 /// of the pattern cannot match, the whole match fails.
13 Possessive,
14}
15
16impl Reluctance {
17 pub fn suffix(&self) -> &'static str {
18 match self {
19 Reluctance::Greedy => "",
20 Reluctance::Lazy => "?",
21 Reluctance::Possessive => "+",
22 }
23 }
24}