use std::fmt;
use std::path;
use reflection;
use utils;
use Predicate;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ExistencePredicate {
exists: bool,
}
impl Predicate<path::Path> for ExistencePredicate {
fn eval(&self, path: &path::Path) -> bool {
path.exists() == self.exists
}
fn find_case<'a>(
&'a self,
expected: bool,
variable: &path::Path,
) -> Option<reflection::Case<'a>> {
utils::default_find_case(self, expected, variable)
}
}
impl reflection::PredicateReflection for ExistencePredicate {}
impl fmt::Display for ExistencePredicate {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}(var)", if self.exists { "exists" } else { "missing" })
}
}
pub fn exists() -> ExistencePredicate {
ExistencePredicate { exists: true }
}
pub fn missing() -> ExistencePredicate {
ExistencePredicate { exists: false }
}