lemma/inversion/
target.rs1use crate::evaluation::operations::VetoType;
4use crate::planning::semantics::LiteralValue;
5use crate::OperationResult;
6use serde::Serialize;
7
8#[derive(Debug, Clone, PartialEq, Serialize)]
10pub struct Target {
11 pub op: TargetOp,
13
14 pub outcome: Option<OperationResult>,
17}
18
19#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize)]
21pub enum TargetOp {
22 Eq,
24 Neq,
26 Lt,
28 Lte,
30 Gt,
32 Gte,
34}
35
36impl Target {
37 pub fn value(value: LiteralValue) -> Self {
39 Self {
40 op: TargetOp::Eq,
41 outcome: Some(OperationResult::Value(Box::new(value))),
42 }
43 }
44
45 pub fn veto(message: Option<String>) -> Self {
47 Self {
48 op: TargetOp::Eq,
49 outcome: Some(OperationResult::Veto(VetoType::UserDefined { message })),
50 }
51 }
52
53 pub fn any_veto() -> Self {
55 Self::veto(None)
56 }
57
58 pub fn any_value() -> Self {
60 Self {
61 op: TargetOp::Eq,
62 outcome: None,
63 }
64 }
65
66 pub fn with_op(op: TargetOp, outcome: OperationResult) -> Self {
68 Self {
69 op,
70 outcome: Some(outcome),
71 }
72 }
73
74 pub fn format(&self) -> String {
76 let op_str = match self.op {
77 TargetOp::Eq => "=",
78 TargetOp::Neq => "is not",
79 TargetOp::Lt => "<",
80 TargetOp::Lte => "<=",
81 TargetOp::Gt => ">",
82 TargetOp::Gte => ">=",
83 };
84
85 let value_str = match &self.outcome {
86 None => "any".to_string(),
87 Some(OperationResult::Value(v)) => v.to_string(),
88 Some(OperationResult::Veto(reason)) => format!("veto({reason})"),
89 };
90
91 format!("{} {}", op_str, value_str)
92 }
93}