use std::sync::Arc;
use super::FileAccessLog;
pub trait FileAccessLogSpecification: Send + Sync {
fn is_satisfied_by(&self, entity: &FileAccessLog) -> bool;
fn and<S: FileAccessLogSpecification + 'static>(self, other: S) -> AndFileAccessLogSpec
where
Self: Sized + 'static,
{
AndFileAccessLogSpec::new(Box::new(self), Box::new(other))
}
fn or<S: FileAccessLogSpecification + 'static>(self, other: S) -> OrFileAccessLogSpec
where
Self: Sized + 'static,
{
OrFileAccessLogSpec::new(Box::new(self), Box::new(other))
}
fn not(self) -> NotFileAccessLogSpec
where
Self: Sized + 'static,
{
NotFileAccessLogSpec::new(Box::new(self))
}
}
pub struct AndFileAccessLogSpec {
left: Box<dyn FileAccessLogSpecification>,
right: Box<dyn FileAccessLogSpecification>,
}
impl AndFileAccessLogSpec {
pub fn new(left: Box<dyn FileAccessLogSpecification>, right: Box<dyn FileAccessLogSpecification>) -> Self {
Self { left, right }
}
}
impl FileAccessLogSpecification for AndFileAccessLogSpec {
fn is_satisfied_by(&self, entity: &FileAccessLog) -> bool {
self.left.is_satisfied_by(entity) && self.right.is_satisfied_by(entity)
}
}
pub struct OrFileAccessLogSpec {
left: Box<dyn FileAccessLogSpecification>,
right: Box<dyn FileAccessLogSpecification>,
}
impl OrFileAccessLogSpec {
pub fn new(left: Box<dyn FileAccessLogSpecification>, right: Box<dyn FileAccessLogSpecification>) -> Self {
Self { left, right }
}
}
impl FileAccessLogSpecification for OrFileAccessLogSpec {
fn is_satisfied_by(&self, entity: &FileAccessLog) -> bool {
self.left.is_satisfied_by(entity) || self.right.is_satisfied_by(entity)
}
}
pub struct NotFileAccessLogSpec {
spec: Box<dyn FileAccessLogSpecification>,
}
impl NotFileAccessLogSpec {
pub fn new(spec: Box<dyn FileAccessLogSpecification>) -> Self {
Self { spec }
}
}
impl FileAccessLogSpecification for NotFileAccessLogSpec {
fn is_satisfied_by(&self, entity: &FileAccessLog) -> bool {
!self.spec.is_satisfied_by(entity)
}
}