logic/operators/
not.rs

1use crate::{Formula, Metric};
2
3pub struct Not<P> {
4    phi: P,
5}
6
7impl<P> Not<P> {
8    pub fn new(phi: P) -> Not<P> {
9        Not { phi }
10    }
11}
12
13impl<T, P> Formula<T> for Not<P>
14where
15    P: Formula<T>,
16{
17    type Error = P::Error;
18
19    fn satisfied_by(&self, value: &T) -> Result<bool, Self::Error> {
20        Ok(!self.phi.satisfied_by(value)?)
21    }
22}
23
24impl<T, U> Metric<T> for Not<U>
25where
26    U: Metric<T>,
27{
28    type Error = U::Error;
29
30    fn distance(&self, value: &T) -> Result<f64, Self::Error> {
31        Ok(-self.phi.distance(value)?)
32    }
33}