mockall

Trait PredicateStrExt

pub trait PredicateStrExt: Predicate<str> + Sized {
    // Provided methods
    fn trim(self) -> TrimPredicate<Self> { ... }
    fn from_utf8(self) -> Utf8Predicate<Self> { ... }
    fn normalize(self) -> NormalizedPredicate<Self> { ... }
}
Expand description

Predicate extension adapting a str Predicate.

Provided Methods§

fn trim(self) -> TrimPredicate<Self>

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 from_utf8(self) -> Utf8Predicate<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));

fn normalize(self) -> NormalizedPredicate<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"));

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

§

impl<P> PredicateStrExt for P
where P: Predicate<str>,