// Copyright (c) 2018 The predicates-rs Project Developers. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms.
use std::fmt; use std::fs; use std::io::{self, Read}; use std::path;
/// Predicate adapter that converts a `path` predicate to a byte predicate on its content. /// /// This is created by `pred.from_file_path()`. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pubstruct FileContentPredicate<P> where
P: Predicate<[u8]>,
{
p: P,
}
impl<P> FileContentPredicate<P> where
P: Predicate<[u8]>,
{ fn eval(&self, path: &path::Path) -> io::Result<bool> { let buffer = read_file(path)?;
Ok(self.p.eval(&buffer))
}
}
impl<P> reflection::PredicateReflection for FileContentPredicate<P> where
P: Predicate<[u8]>,
{ fn children<'a>(&'a self) -> Box<dyn Iterator<Item = reflection::Child<'a>> + 'a> { let params = vec![reflection::Child::new("predicate", &self.p)]; Box::new(params.into_iter())
}
}
impl<P> fmt::Display for FileContentPredicate<P> where
P: Predicate<[u8]>,
{ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.p.fmt(f)
}
}
impl<P> Predicate<path::Path> for FileContentPredicate<P> where
P: Predicate<[u8]>,
{ fn eval(&self, path: &path::Path) -> bool { self.eval(path).unwrap_or(false)
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.