// Copyright (c) 2018 The predicates-rs Project Developers. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/license/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.
/// Predicate adapter that trims the variable being tested. /// /// This is created by `pred.trim()`. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pubstruct TrimPredicate<P> where
P: Predicate<str>,
{
p: P,
}
impl<P> Predicate<str> for TrimPredicate<P> where
P: Predicate<str>,
{ fn eval(&self, variable: &str) -> bool { self.p.eval(variable.trim())
}
impl<P> reflection::PredicateReflection for TrimPredicate<P> where
P: Predicate<str>,
{ 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 TrimPredicate<P> where
P: Predicate<str>,
{ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.p.fmt(f)
}
}
/// Predicate adapter that converts a `str` predicate to byte predicate. /// /// This is created by `pred.from_utf8()`. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pubstruct Utf8Predicate<P> where
P: Predicate<str>,
{
p: P,
}
impl<P> Predicate<ffi::OsStr> for Utf8Predicate<P> where
P: Predicate<str>,
{ fn eval(&self, variable: &ffi::OsStr) -> bool {
variable.to_str().map(|s| self.p.eval(s)).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.