rpn_cli/
meaning.rs

1use crate::error::EngineError;
2
3#[derive(Debug, PartialEq, Copy, Clone)]
4pub enum Meaning {
5    Plain,
6    Delta,
7    Time,
8}
9
10impl Meaning {
11    pub fn combine(
12        self,
13        other: Self,
14        plain: fn(Self) -> Result<Self, EngineError>,
15        delta: fn(Self) -> Result<Self, EngineError>,
16        time: fn(Self) -> Result<Self, EngineError>,
17    ) -> Result<Self, EngineError> {
18        match self {
19            Self::Plain => plain(other),
20            Self::Delta => delta(other),
21            Self::Time => time(other),
22        }
23    }
24
25    pub fn pdt(self) -> Result<Self, EngineError> {
26        match self {
27            Self::Plain => Ok(Self::Plain),
28            Self::Delta => Ok(Self::Delta),
29            Self::Time => Ok(Self::Time),
30        }
31    }
32
33    pub fn pdx(self) -> Result<Self, EngineError> {
34        match self {
35            Self::Plain => Ok(Self::Plain),
36            Self::Delta => Ok(Self::Delta),
37            Self::Time => Err(EngineError::BadTimeOp),
38        }
39    }
40
41    pub fn pxx(self) -> Result<Self, EngineError> {
42        match self {
43            Self::Plain => Ok(Self::Plain),
44            Self::Delta => Err(EngineError::BadTimeOp),
45            Self::Time => Err(EngineError::BadTimeOp),
46        }
47    }
48
49    pub fn ddt(self) -> Result<Self, EngineError> {
50        match self {
51            Self::Plain => Ok(Self::Delta),
52            Self::Delta => Ok(Self::Delta),
53            Self::Time => Ok(Self::Time),
54        }
55    }
56
57    pub fn ddx(self) -> Result<Self, EngineError> {
58        match self {
59            Self::Plain => Ok(Self::Delta),
60            Self::Delta => Ok(Self::Delta),
61            Self::Time => Err(EngineError::BadTimeOp),
62        }
63    }
64
65    pub fn dxx(self) -> Result<Self, EngineError> {
66        match self {
67            Self::Plain => Ok(Self::Delta),
68            Self::Delta => Err(EngineError::BadTimeOp),
69            Self::Time => Err(EngineError::BadTimeOp),
70        }
71    }
72
73    pub fn ttd(self) -> Result<Self, EngineError> {
74        match self {
75            Self::Plain => Ok(Self::Time),
76            Self::Delta => Ok(Self::Time),
77            Self::Time => Ok(Self::Delta),
78        }
79    }
80
81    pub fn ttx(self) -> Result<Self, EngineError> {
82        match self {
83            Self::Plain => Ok(Self::Time),
84            Self::Delta => Ok(Self::Time),
85            Self::Time => Err(EngineError::BadTimeOp),
86        }
87    }
88
89    pub fn xxx(self) -> Result<Self, EngineError> {
90        match self {
91            Self::Plain => Err(EngineError::BadTimeOp),
92            Self::Delta => Err(EngineError::BadTimeOp),
93            Self::Time => Err(EngineError::BadTimeOp),
94        }
95    }
96}