lemma/
operation_result.rs1use crate::semantic::LiteralValue;
2use crate::LemmaError;
3
4#[derive(Debug, Clone, PartialEq)]
6pub enum OperationResult {
7 Value(LiteralValue),
9 Veto(Option<String>),
11}
12
13impl OperationResult {
14 pub fn is_vetoed(&self) -> bool {
16 matches!(self, OperationResult::Veto(_))
17 }
18
19 pub fn value(&self) -> Option<&LiteralValue> {
21 match self {
22 OperationResult::Value(v) => Some(v),
23 OperationResult::Veto(_) => None,
24 }
25 }
26
27 pub fn expect_value(&self, context: &str) -> Result<&LiteralValue, LemmaError> {
30 match self {
31 OperationResult::Value(v) => Ok(v),
32 OperationResult::Veto(msg) => Err(LemmaError::Engine(format!(
33 "Expected value in {}, but got veto{}",
34 context,
35 msg.as_ref().map(|m| format!(": {}", m)).unwrap_or_default()
36 ))),
37 }
38 }
39
40 pub fn veto_message(&self) -> Option<&Option<String>> {
42 match self {
43 OperationResult::Veto(msg) => Some(msg),
44 OperationResult::Value(_) => None,
45 }
46 }
47}