1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use std::collections::HashMap;

use crate::trace::Trace;
use crate::Formula;

pub struct Proposition {
    name: String,
}

impl Proposition {
    pub fn new(name: &str) -> Proposition {
        Proposition {
            name: String::from(name),
        }
    }
}

impl Formula<HashMap<String, bool>> for Proposition {
    type Error = super::error::Error;

    fn satisfied_by(&self, value: &HashMap<String, bool>) -> Result<bool, Self::Error> {
        value
            .get(&self.name)
            .cloned()
            .ok_or_else(|| super::error::Error::MissingVariable(self.name.clone()))
    }
}

impl Formula<Trace<HashMap<String, bool>>> for Proposition {
    type Error = super::error::TimedError;

    fn satisfied_by(&self, trace: &Trace<HashMap<String, bool>>) -> Result<bool, Self::Error> {
        let first_state = trace.first_state().ok_or(super::error::TimedError::EmptyTrace)?;

        self.satisfied_by(first_state.state)
            .map_err(|error| super::error::TimedError::ValuationError(first_state.time, error))
    }
}