logic/expressions/
proposition.rs

1use std::collections::HashMap;
2
3use crate::trace::Trace;
4use crate::Formula;
5
6pub struct Proposition {
7    name: String,
8}
9
10impl Proposition {
11    pub fn new(name: &str) -> Proposition {
12        Proposition {
13            name: String::from(name),
14        }
15    }
16}
17
18impl Formula<HashMap<String, bool>> for Proposition {
19    type Error = super::error::Error;
20
21    fn satisfied_by(&self, value: &HashMap<String, bool>) -> Result<bool, Self::Error> {
22        value
23            .get(&self.name)
24            .cloned()
25            .ok_or_else(|| super::error::Error::MissingVariable(self.name.clone()))
26    }
27}
28
29impl Formula<Trace<HashMap<String, bool>>> for Proposition {
30    type Error = super::error::TimedError;
31
32    fn satisfied_by(&self, trace: &Trace<HashMap<String, bool>>) -> Result<bool, Self::Error> {
33        let first_state = trace.first_state().ok_or(super::error::TimedError::EmptyTrace)?;
34
35        self.satisfied_by(first_state.state)
36            .map_err(|error| super::error::TimedError::ValuationError(first_state.time, error))
37    }
38}