oni_comb_parser_rs/core/
committed_status.rs

1/// A structure representing the commit status of the parser.<br/>
2/// パーサのコミット状態を表す構造体。
3#[derive(Debug, Clone, Copy, PartialOrd, PartialEq)]
4pub enum CommittedStatus {
5  Committed,
6  Uncommitted,
7}
8
9impl From<bool> for CommittedStatus {
10  fn from(value: bool) -> Self {
11    if value {
12      CommittedStatus::Committed
13    } else {
14      CommittedStatus::Uncommitted
15    }
16  }
17}
18
19impl CommittedStatus {
20  /// Returns whether committed or not.
21  pub fn is_committed(&self) -> bool {
22    match self {
23      CommittedStatus::Committed => true,
24      CommittedStatus::Uncommitted => false,
25    }
26  }
27
28  /// Returns whether uncommitted or not.
29  pub fn is_uncommitted(&self) -> bool {
30    !self.is_committed()
31  }
32
33  /// Compose [CommittedStatus].
34  ///
35  /// If either one is already committed, it returns it. Otherwise, it returns uncommitted.
36  pub fn or(&self, other: Self) -> Self {
37    match (self, other) {
38      (CommittedStatus::Committed, _) => CommittedStatus::Committed,
39      (_, CommittedStatus::Committed) => CommittedStatus::Committed,
40      _ => CommittedStatus::Uncommitted,
41    }
42  }
43}