// 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.
//! Definition of `Predicate` for wrapping a `Fn(&T) -> bool`
/// Predicate that wraps a function over a reference that returns a `bool`. /// This type is returned by the `predicate::function` function. #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)] pubstruct FnPredicate<F, T> where
F: Fn(&T) -> bool,
T: ?Sized,
{
function: F,
name: &'static str,
_phantom: PhantomData<T>,
}
unsafeimpl<F, T> Send for FnPredicate<F, T> where
F: Send + Fn(&T) -> bool,
T: ?Sized,
{
}
unsafeimpl<F, T> Sync for FnPredicate<F, T> where
F: Sync + Fn(&T) -> bool,
T: ?Sized,
{
}
impl<F, T> FnPredicate<F, T> where
F: Fn(&T) -> bool,
T: ?Sized,
{ /// Provide a descriptive name for this function. /// /// # Examples /// /// ``` /// use predicates::prelude::*; /// /// struct Example { /// string: String, /// number: i32, /// } /// /// let string_check = predicate::function(|x: &Example| x.string == "hello") /// .fn_name("is_hello"); /// println!("predicate: {}", string_check); /// ``` pubfn fn_name(mutself, name: &'static str) -> Self { self.name = name; self
}
}
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.