TypedPredicate

Struct TypedPredicate 

Source
pub struct TypedPredicate<T: ValueLike>(/* private fields */);
Expand description

Represents a typed Predicate, ensuring that only valid conditions are used for a given type

Implementations§

Source§

impl<T: ValueLike> TypedPredicate<T>

Source

pub fn lambda<F: 'static + Fn(T) -> bool>(f: F) -> Self

Creates a new typed predicate for Predicate::Lambda

§Examples
use entity::TypedPredicate as P;

let p = P::lambda(|x| x > 3);
assert_eq!(p.check(4), true);
assert_eq!(p.check(1), false);
Source§

impl<T: ValueLike> TypedPredicate<T>

Source

pub fn new(predicate: Predicate) -> Self

Creates a new typed predicate from an untyped predicate

Source

pub fn as_untyped(&self) -> &Predicate

Returns a reference to the untyped Predicate wrapped by this typed instance

Source

pub fn check(&self, value: T) -> bool

Checks if the typed predicate is satisfied by the given value

NOTE: This consumes the value instead of the untyped version that merely references the value

Source

pub fn always() -> Self

Creates a new typed predicate for Predicate::Always

§Examples
use entity::TypedPredicate as P;

let p = P::always();
assert_eq!(p.check(1), true);
Source

pub fn never() -> Self

Creates a new typed predicate for Predicate::Never

§Examples
use entity::TypedPredicate as P;

let p = P::never();
assert_eq!(p.check(1), false);
Source

pub fn and<P: Into<TypedPredicate<T>>, I: IntoIterator<Item = P>>(i: I) -> Self

Creates a new typed predicate for Predicate::And

§Examples
use entity::TypedPredicate as P;

let p = P::and(vec![
    P::greater_than(1),
    P::less_than(3),
]);
assert_eq!(p.check(2), true);
assert_eq!(p.check(1), false);
Source

pub fn not<P: Into<TypedPredicate<T>>>(p: P) -> Self

Creates a new typed predicate for Predicate::Not

§Examples
use entity::TypedPredicate as P;

let p = P::not(P::greater_than(1));
assert_eq!(p.check(1), true);
assert_eq!(p.check(2), false);
Source

pub fn or<P: Into<TypedPredicate<T>>, I: IntoIterator<Item = P>>(i: I) -> Self

Creates a new typed predicate for Predicate::Or

§Examples
use entity::TypedPredicate as P;

let p = P::or(vec![P::greater_than(1), P::equals(1)]);
assert_eq!(p.check(1), true);
assert_eq!(p.check(2), true);
assert_eq!(p.check(0), false);
Source

pub fn xor<P: Into<TypedPredicate<T>>, I: IntoIterator<Item = P>>(i: I) -> Self

Creates a new typed predicate for Predicate::Xor

§Examples
use entity::TypedPredicate as P;

let p = P::xor(vec![P::greater_than(1), P::greater_than(2)]);
assert_eq!(p.check(2), true);
assert_eq!(p.check(3), false);
assert_eq!(p.check(1), false);
Source§

impl<T: ValueLike, C: IntoIterator<Item = T> + ValueLike> TypedPredicate<C>

Implementation for collections with a singular type. For std::collections::HashMap and similar types, use the MapTypedPredicate instead.

Source

pub fn any<P: Into<TypedPredicate<T>>>(p: P) -> Self

Creates a new typed predicate for Predicate::Any

§Examples
use entity::TypedPredicate as P;

let p = P::any(P::equals(3));
assert_eq!(p.check(vec![1, 2, 3]), true);

let p = P::any(P::equals(4));
assert_eq!(p.check(vec![1, 2, 3]), false);
Source

pub fn contains(value: T) -> Self

Creates a new typed predicate for Predicate::Contains

§Examples
use entity::TypedPredicate as P;

let p = P::contains(3);
assert_eq!(p.check(vec![1, 2, 3]), true);

let p = P::contains(4);
assert_eq!(p.check(vec![1, 2, 3]), false);
Source

pub fn contains_all<I: IntoIterator<Item = T>>(i: I) -> Self

Creates a new typed predicate for Predicate::ContainsAll

§Examples
use entity::TypedPredicate as P;

let p = P::contains_all(vec![1, 3]);
assert_eq!(p.check(vec![1, 2, 3]), true);

let p = P::contains_all(vec![1, 4]);
assert_eq!(p.check(vec![1, 2, 3]), false);
Source

pub fn contains_any<I: IntoIterator<Item = T>>(i: I) -> Self

Creates a new typed predicate for Predicate::ContainsAny

§Examples
use entity::TypedPredicate as P;

let p = P::contains_any(vec![1, 4]);
assert_eq!(p.check(vec![1, 2, 3]), true);

let p = P::contains_any(vec![4, 5]);
assert_eq!(p.check(vec![1, 2, 3]), false);
Source§

impl<T: ValueLike> TypedPredicate<T>

Source

pub fn equals(value: T) -> Self

Creates a new typed predicate for Predicate::Equals

§Examples
use entity::TypedPredicate as P;

let p = P::equals(3);
assert_eq!(p.check(3), true);
assert_eq!(p.check(2), false);
Source

pub fn greater_than(value: T) -> Self

Creates a new typed predicate for Predicate::GreaterThan

§Examples
use entity::TypedPredicate as P;

let p = P::greater_than(3);
assert_eq!(p.check(4), true);
assert_eq!(p.check(3), false);
Source

pub fn greater_than_or_equals(value: T) -> Self

Creates a new typed predicate for Predicate::GreaterThanOrEquals

§Examples
use entity::TypedPredicate as P;

let p = P::greater_than_or_equals(3);
assert_eq!(p.check(4), true);
assert_eq!(p.check(3), true);
assert_eq!(p.check(2), false);
Source

pub fn in_range(range: RangeInclusive<T>) -> Self

Creates a new typed predicate for Predicate::InRange

§Examples
use entity::TypedPredicate as P;

let p = P::in_range(3..=5);
assert_eq!(p.check(2), false);
assert_eq!(p.check(3), true);
assert_eq!(p.check(4), true);
assert_eq!(p.check(5), true);
assert_eq!(p.check(6), false);
Source

pub fn in_set<I: IntoIterator<Item = T>>(set: I) -> Self

Creates a new typed predicate for Predicate::InSet

§Examples
use entity::TypedPredicate as P;

let p = P::in_set(vec![1, 2, 3]);
assert_eq!(p.check(0), false);
assert_eq!(p.check(1), true);
assert_eq!(p.check(2), true);
assert_eq!(p.check(3), true);
assert_eq!(p.check(4), false);
Source

pub fn less_than(value: T) -> Self

Creates a new typed predicate for Predicate::LessThan

§Examples
use entity::TypedPredicate as P;

let p = P::less_than(3);
assert_eq!(p.check(2), true);
assert_eq!(p.check(3), false);
Source

pub fn less_than_or_equals(value: T) -> Self

Creates a new typed predicate for Predicate::LessThanOrEquals

§Examples
use entity::TypedPredicate as P;

let p = P::less_than_or_equals(3);
assert_eq!(p.check(2), true);
assert_eq!(p.check(3), true);
assert_eq!(p.check(4), false);
Source

pub fn not_equals(value: T) -> Self

Creates a new typed predicate for Predicate::NotEquals

use entity::TypedPredicate as P;

let p = P::not_equals(3);
assert_eq!(p.check(2), true);
assert_eq!(p.check(3), false);
Source

pub fn not_in_range(range: RangeInclusive<T>) -> Self

Creates a new typed predicate for Predicate::NotInRange

§Examples
use entity::TypedPredicate as P;

let p = P::not_in_range(3..=5);
assert_eq!(p.check(2), true);
assert_eq!(p.check(3), false);
assert_eq!(p.check(4), false);
assert_eq!(p.check(5), false);
assert_eq!(p.check(6), true);
Source

pub fn not_in_set<I: IntoIterator<Item = T>>(set: I) -> Self

Creates a new typed predicate for Predicate::NotInSet

§Examples
use entity::TypedPredicate as P;

let p = P::not_in_set(vec![1, 2, 3]);
assert_eq!(p.check(0), true);
assert_eq!(p.check(1), false);
assert_eq!(p.check(2), false);
assert_eq!(p.check(3), false);
assert_eq!(p.check(4), true);
Source§

impl<T: ValueLike> TypedPredicate<HashMap<String, T>>

Source

pub fn has_key<K: Into<String>>(k: K) -> Self

Creates a new typed predicate for Predicate::HasKey

§Examples
use entity::TypedPredicate as P;
use std::collections::HashMap;

let map: HashMap<String, u32> = vec![
    (String::from("a"), 1),
    (String::from("b"), 2),
    (String::from("c"), 3),
].into_iter().collect();

let p = P::has_key("a");
assert_eq!(p.check(map.clone()), true);

let p = P::has_key("d");
assert_eq!(p.check(map), false);
Source

pub fn has_key_where_value<K: Into<String>, P: Into<TypedPredicate<T>>>( k: K, p: P, ) -> Self

Creates a new typed predicate for Predicate::HasKeyWhereValue

§Examples
use entity::TypedPredicate as P;
use std::collections::HashMap;

let map: HashMap<String, u32> = vec![
    (String::from("a"), 1),
    (String::from("b"), 2),
    (String::from("c"), 3),
].into_iter().collect();

let p = P::has_key_where_value("a", P::equals(1));
assert_eq!(p.check(map.clone()), true);

let p = P::has_key_where_value("b", P::equals(1));
assert_eq!(p.check(map.clone()), false);

let p = P::has_key_where_value("d", P::equals(1));
assert_eq!(p.check(map), false);
Source§

impl<T: ValueLike> TypedPredicate<Option<T>>

Source

pub fn is_none() -> Self

Creates a new typed predicate for Predicate::IsNone

§Examples
use entity::TypedPredicate as P;

let p = P::is_none();

let v = None::<u32>;
assert_eq!(p.check(v), true);

let v = Some(3);
assert_eq!(p.check(v), false);
Source

pub fn not_none_and<P: Into<TypedPredicate<T>>>(p: P) -> Self

Creates a new typed predicate for Predicate::NotNoneAnd

§Examples
use entity::TypedPredicate as P;

let p = P::not_none_and(P::equals(3));

let v = Some(3);
assert_eq!(p.check(v), true);

let v = Some(2);
assert_eq!(p.check(v), false);

let v = None::<u32>;
assert_eq!(p.check(v), false);
Source

pub fn none_or<P: Into<TypedPredicate<T>>>(p: P) -> Self

Creates a new typed predicate for Predicate::NoneOr

§Examples
use entity::TypedPredicate as P;

let p = P::none_or(P::equals(3));

let v = Some(3);
assert_eq!(p.check(v), true);

let v = None::<u32>;
assert_eq!(p.check(v), true);

let v = Some(2);
assert_eq!(p.check(v), false);
Source§

impl TypedPredicate<String>

Source

pub fn text_ends_with<S: Into<String>>(s: S) -> Self

Creates a new typed predicate for Predicate::TextEndsWith

§Examples
use entity::TypedPredicate as P;

let p = P::text_ends_with("text");

assert_eq!(p.check(String::from("some text")), true);
assert_eq!(p.check(String::from("text some")), false);
Source

pub fn text_ends_with_case_insensitive<S: Into<String>>(s: S) -> Self

Creates a new typed predicate for Predicate::TextEndsWithCaseInsensitive

§Examples
use entity::TypedPredicate as P;

let p = P::text_ends_with_case_insensitive("text");

assert_eq!(p.check(String::from("SOME TEXT")), true);
assert_eq!(p.check(String::from("TEXT SOME")), false);
Source

pub fn text_equals_case_insensitive<S: Into<String>>(s: S) -> Self

Creates a new typed predicate for Predicate::TextEqualsCaseInsensitive

§Examples
use entity::TypedPredicate as P;

let p = P::text_equals_case_insensitive("text");

assert_eq!(p.check(String::from("TEXT")), true);
assert_eq!(p.check(String::from("OTHER")), false);
Source

pub fn text_in_set_case_insensitive<S: Into<String>, I: IntoIterator<Item = S>>( i: I, ) -> Self

Creates a new typed predicate for Predicate::TextInSetCaseInsensitive

§Examples
use entity::TypedPredicate as P;

let p = P::text_in_set_case_insensitive(vec!["one", "two", "three"]);

assert_eq!(p.check(String::from("TWO")), true);
assert_eq!(p.check(String::from("FOUR")), false);
Source

pub fn text_not_equals_case_insensitive<S: Into<String>>(s: S) -> Self

Creates a new typed predicate for Predicate::TextNotEqualsCaseInsensitive

§Examples
use entity::TypedPredicate as P;

let p = P::text_not_equals_case_insensitive("text");

assert_eq!(p.check(String::from("OTHER")), true);
assert_eq!(p.check(String::from("TEXT")), false);
Source

pub fn text_starts_with<S: Into<String>>(s: S) -> Self

Creates a new typed predicate for Predicate::TextStartsWith

§Examples
use entity::TypedPredicate as P;

let p = P::text_starts_with("text");

assert_eq!(p.check(String::from("text some")), true);
assert_eq!(p.check(String::from("some text")), false);
Source

pub fn text_starts_with_case_insensitive<S: Into<String>>(s: S) -> Self

Creates a new typed predicate for Predicate::TextStartsWithCaseInsensitive

§Examples
use entity::TypedPredicate as P;

let p = P::text_starts_with_case_insensitive("text");

assert_eq!(p.check(String::from("TEXT SOME")), true);
assert_eq!(p.check(String::from("SOME TEXT")), false);
Source

pub fn text_contained_in<S: Into<String>>(s: S) -> Self

Creates a new typed predicate for Predicate::TextContainedIn

§Examples
use entity::TypedPredicate as P;

let p = P::text_contained_in("text");

assert_eq!(p.check(String::from("ex")), true);
assert_eq!(p.check(String::from("tt")), false);
Source

pub fn text_contained_in_case_insensitive<S: Into<String>>(s: S) -> Self

Creates a new typed predicate for Predicate::TextContainedInCaseInsensitive

§Examples
use entity::TypedPredicate as P;

let p = P::text_contained_in_case_insensitive("text");

assert_eq!(p.check(String::from("EX")), true);
assert_eq!(p.check(String::from("TT")), false);
Source

pub fn text_contains_all<S: Into<String>, I: IntoIterator<Item = S>>( i: I, ) -> Self

Creates a new typed predicate for Predicate::TextContainsAll

§Examples
use entity::TypedPredicate as P;

let p = P::text_contains_all(vec!["one", "two", "three"]);

assert_eq!(p.check(String::from("my one and two and three text")), true);
assert_eq!(p.check(String::from("my one and two text")), false);
Source

pub fn text_contains_all_case_insensitive<S: Into<String>, I: IntoIterator<Item = S>>( i: I, ) -> Self

Creates a new typed predicate for Predicate::TextContainsAllCaseInsensitive

§Examples
use entity::TypedPredicate as P;

let p = P::text_contains_all_case_insensitive(vec!["one", "two", "three"]);

assert_eq!(p.check(String::from("MY ONE AND TWO AND THREE TEXT")), true);
assert_eq!(p.check(String::from("MY ONE AND TWO TEXT")), false);
Source

pub fn text_contains_any<S: Into<String>, I: IntoIterator<Item = S>>( i: I, ) -> Self

Creates a new typed predicate for Predicate::TextContainsAny

§Examples
use entity::TypedPredicate as P;

let p = P::text_contains_any(vec!["one", "two", "three"]);

assert_eq!(p.check(String::from("my one text")), true);
assert_eq!(p.check(String::from("my four text")), false);
Source

pub fn text_contains_any_case_insensitive<S: Into<String>, I: IntoIterator<Item = S>>( i: I, ) -> Self

Creates a new typed predicate for Predicate::TextContainsAnyCaseInsensitive

§Examples
use entity::TypedPredicate as P;

let p = P::text_contains_any_case_insensitive(vec!["one", "two", "three"]);

assert_eq!(p.check(String::from("MY ONE TEXT")), true);
assert_eq!(p.check(String::from("MY FOUR TEXT")), false);
Source

pub fn text_ends_with_any<S: Into<String>, I: IntoIterator<Item = S>>( i: I, ) -> Self

Creates a new typed predicate for Predicate::TextEndsWithAny

§Examples
use entity::TypedPredicate as P;

let p = P::text_ends_with_any(vec!["one", "two", "three"]);

assert_eq!(p.check(String::from("my text one")), true);
assert_eq!(p.check(String::from("one my text")), false);
Source

pub fn text_ends_with_any_case_insensitive<S: Into<String>, I: IntoIterator<Item = S>>( i: I, ) -> Self

Creates a new typed predicate for Predicate::TextEndsWithAnyCaseInsensitive

§Examples
use entity::TypedPredicate as P;

let p = P::text_ends_with_any_case_insensitive(vec!["one", "two", "three"]);

assert_eq!(p.check(String::from("MY TEXT ONE")), true);
assert_eq!(p.check(String::from("ONE MY TEXT")), false);
Source

pub fn text_starts_with_any<S: Into<String>, I: IntoIterator<Item = S>>( i: I, ) -> Self

Creates a new typed predicate for Predicate::TextStartsWithAny

§Examples
use entity::TypedPredicate as P;

let p = P::text_starts_with_any(vec!["one", "two", "three"]);

assert_eq!(p.check(String::from("one my text")), true);
assert_eq!(p.check(String::from("my text one")), false);
Source

pub fn text_starts_with_any_case_insensitive<S: Into<String>, I: IntoIterator<Item = S>>( i: I, ) -> Self

Creates a new typed predicate for Predicate::TextStartsWithAnyCaseInsensitive

§Examples
use entity::TypedPredicate as P;

let p = P::text_starts_with_any_case_insensitive(vec!["one", "two", "three"]);

assert_eq!(p.check(String::from("ONE MY TEXT")), true);
assert_eq!(p.check(String::from("MY TEXT ONE")), false);

Trait Implementations§

Source§

impl<T: ValueLike> BitAnd for TypedPredicate<T>

Source§

fn bitand(self, rhs: Self) -> Self

Shorthand to produce Predicate::And

Source§

type Output = TypedPredicate<T>

The resulting type after applying the & operator.
Source§

impl<T: ValueLike> BitOr for TypedPredicate<T>

Source§

fn bitor(self, rhs: Self) -> Self

Shorthand to produce Predicate::Or

Source§

type Output = TypedPredicate<T>

The resulting type after applying the | operator.
Source§

impl<T: ValueLike> BitXor for TypedPredicate<T>

Source§

fn bitxor(self, rhs: Self) -> Self

Shorthand to produce Predicate::Xor

Source§

type Output = TypedPredicate<T>

The resulting type after applying the ^ operator.
Source§

impl<T: Clone + ValueLike> Clone for TypedPredicate<T>

Source§

fn clone(&self) -> TypedPredicate<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + ValueLike> Debug for TypedPredicate<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: ValueLike, C: IntoIterator<Item = (String, T)> + ValueLike> From<MapTypedPredicate<T, C>> for TypedPredicate<C>

Source§

fn from(map_typed_predicate: MapTypedPredicate<T, C>) -> Self

Converts to this type from the input type.
Source§

impl<T: ValueLike> From<Predicate> for TypedPredicate<T>

Source§

fn from(predicate: Predicate) -> Self

Converts to this type from the input type.
Source§

impl<T: ValueLike, C: IntoIterator<Item = (String, T)> + ValueLike> From<TypedPredicate<C>> for MapTypedPredicate<T, C>

Source§

fn from(typed_predicate: TypedPredicate<C>) -> Self

Converts to this type from the input type.
Source§

impl<T: ValueLike> From<TypedPredicate<T>> for Predicate

Source§

fn from(typed_predicate: TypedPredicate<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: ValueLike> Not for TypedPredicate<T>

Source§

fn not(self) -> Self::Output

Shorthand to produce Predicate::Not

Source§

type Output = TypedPredicate<T>

The resulting type after applying the ! operator.
Source§

impl<T: ValueLike> PartialEq<Predicate> for TypedPredicate<T>

Source§

fn eq(&self, other: &Predicate) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: ValueLike> PartialEq<TypedPredicate<T>> for Predicate

Source§

fn eq(&self, other: &TypedPredicate<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialEq + ValueLike> PartialEq for TypedPredicate<T>

Source§

fn eq(&self, other: &TypedPredicate<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: ValueLike> StructuralPartialEq for TypedPredicate<T>

Auto Trait Implementations§

§

impl<T> Freeze for TypedPredicate<T>

§

impl<T> !RefUnwindSafe for TypedPredicate<T>

§

impl<T> !Send for TypedPredicate<T>

§

impl<T> !Sync for TypedPredicate<T>

§

impl<T> Unpin for TypedPredicate<T>
where T: Unpin,

§

impl<T> !UnwindSafe for TypedPredicate<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsAny for T
where T: 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts reference to Any
Source§

fn as_mut_any(&mut self) -> &mut (dyn Any + 'static)

converts mutable reference to Any
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.