logic/
formula.rs

1use std::rc::Rc;
2use std::sync::Arc;
3
4pub trait Formula<T> {
5    type Error: std::error::Error;
6
7    /// Returns a boolean value indicating whether or not the value satisfies some criteria.
8    fn satisfied_by(&self, value: &T) -> Result<bool, Self::Error>;
9}
10
11impl<T, F: Formula<T> + ?Sized> Formula<T> for &'_ F {
12    type Error = F::Error;
13
14    fn satisfied_by(&self, value: &T) -> Result<bool, Self::Error> {
15        (**self).satisfied_by(value)
16    }
17}
18
19// TODO remove this definition and use Box inside each of the operators with overloading of constructor
20impl<T, F: Formula<T> + ?Sized> Formula<T> for Box<F> {
21    type Error = F::Error;
22
23    fn satisfied_by(&self, value: &T) -> Result<bool, Self::Error> {
24        (**self).satisfied_by(value)
25    }
26}
27
28impl<T, F: Formula<T> + ?Sized> Formula<T> for Rc<F> {
29    type Error = F::Error;
30
31    fn satisfied_by(&self, value: &T) -> Result<bool, Self::Error> {
32        (**self).satisfied_by(value)
33    }
34}
35
36impl<T, F: Formula<T> + ?Sized> Formula<T> for Arc<F> {
37    type Error = F::Error;
38
39    fn satisfied_by(&self, value: &T) -> Result<bool, Self::Error> {
40        (**self).satisfied_by(value)
41    }
42}