// 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)
}
impl<P> reflection::PredicateReflection for Utf8Predicate<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 Utf8Predicate<P> where
P: Predicate<str>,
{ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.p.fmt(f)
}
}
/// `Predicate` extension adapting a `str` Predicate. pubtrait PredicateStrExt where Self: Predicate<str>, Self: Sized,
{ /// Returns a `TrimPredicate` that ensures the data passed to `Self` is trimmed. /// /// # Examples /// /// ``` /// use predicates::prelude::*; /// /// let predicate_fn = predicate::str::is_empty().trim(); /// assert_eq!(true, predicate_fn.eval(" ")); /// assert_eq!(false, predicate_fn.eval(" Hello ")); /// ``` fn trim(self) -> TrimPredicate<Self> {
TrimPredicate { p: self }
}
/// Returns a `Utf8Predicate` that adapts `Self` to a `[u8]` `Predicate`. /// /// # Examples /// /// ``` /// use predicates::prelude::*; /// use std::ffi::OsStr; /// /// let predicate_fn = predicate::str::is_empty().not().from_utf8(); /// assert_eq!(true, predicate_fn.eval(OsStr::new("Hello"))); /// assert_eq!(false, predicate_fn.eval(OsStr::new(""))); /// let variable: &[u8] = b""; /// assert_eq!(false, predicate_fn.eval(variable)); /// ``` #[allow(clippy::wrong_self_convention)] fn from_utf8(self) -> Utf8Predicate<Self> {
Utf8Predicate { p: self }
}
/// Returns a `NormalizedPredicate` that ensures /// the newlines within the data passed to `Self` is normalised. /// /// # Examples /// /// ``` /// use predicates::prelude::*; /// /// let predicate_fn = predicate::eq("Hello World!\n").normalize(); /// assert_eq!(true, predicate_fn.eval("Hello World!\n")); /// assert_eq!(true, predicate_fn.eval("Hello World!\r")); /// assert_eq!(true, predicate_fn.eval("Hello World!\r\n")); /// assert_eq!(false, predicate_fn.eval("Goodbye")); /// ``` /// #[cfg(feature = "normalize-line-endings")] fn normalize(self) -> NormalizedPredicate<Self> {
NormalizedPredicate { p: self }
}
}
impl<P> PredicateStrExt for P where P: Predicate<str> {}
Messung V0.5 in Prozent
¤ 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.0.1Bemerkung:
(vorverarbeitet am 2026-10-02)
¤
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.