// 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.
/// Predicate that checks for empty strings. /// /// This is created by `predicates::str::is_empty`. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pubstruct IsEmptyPredicate {}
/// Creates a new `Predicate` that ensures a str is empty /// /// # Examples /// /// ``` /// use predicates::prelude::*; /// /// let predicate_fn = predicate::str::is_empty(); /// assert_eq!(true, predicate_fn.eval("")); /// assert_eq!(false, predicate_fn.eval("Food World")); /// ``` pubfn is_empty() -> IsEmptyPredicate {
IsEmptyPredicate {}
}
/// Predicate checks start of str /// /// This is created by `predicates::str::starts_with`. #[derive(Debug, Clone, PartialEq, Eq)] pubstruct StartsWithPredicate {
pattern: String,
}
/// Creates a new `Predicate` that ensures a str starts with `pattern` /// /// # Examples /// /// ``` /// use predicates::prelude::*; /// /// let predicate_fn = predicate::str::starts_with("Hello"); /// assert_eq!(true, predicate_fn.eval("Hello World")); /// assert_eq!(false, predicate_fn.eval("Goodbye World")); /// ``` pubfn starts_with<P>(pattern: P) -> StartsWithPredicate where
P: Into<String>,
{
StartsWithPredicate {
pattern: pattern.into(),
}
}
/// Predicate checks end of str /// /// This is created by `predicates::str::ends_with`. #[derive(Debug, Clone, PartialEq, Eq)] pubstruct EndsWithPredicate {
pattern: String,
}
/// Creates a new `Predicate` that ensures a str ends with `pattern` /// /// # Examples /// /// ``` /// use predicates::prelude::*; /// /// let predicate_fn = predicate::str::ends_with("World"); /// assert_eq!(true, predicate_fn.eval("Hello World")); /// assert_eq!(false, predicate_fn.eval("Hello Moon")); /// ``` pubfn ends_with<P>(pattern: P) -> EndsWithPredicate where
P: Into<String>,
{
EndsWithPredicate {
pattern: pattern.into(),
}
}
/// Predicate that checks for patterns. /// /// This is created by `predicates::str::contains`. #[derive(Debug, Clone, PartialEq, Eq)] pubstruct ContainsPredicate {
pattern: String,
}
impl ContainsPredicate { /// Require a specific count of matches. /// /// # Examples /// /// ``` /// use predicates::prelude::*; /// /// let predicate_fn = predicate::str::contains("Two").count(2); /// assert_eq!(true, predicate_fn.eval("One Two Three Two One")); /// assert_eq!(false, predicate_fn.eval("One Two Three")); /// ``` pubfn count(self, count: usize) -> MatchesPredicate {
MatchesPredicate {
pattern: self.pattern,
count,
}
}
}
/// Predicate that checks for repeated patterns. /// /// This is created by `predicates::str::contains(...).count`. #[derive(Debug, Clone, PartialEq, Eq)] pubstruct MatchesPredicate {
pattern: String,
count: usize,
}
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.