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>
impl<T: ValueLike> TypedPredicate<T>
Source§impl<T: ValueLike> TypedPredicate<T>
impl<T: ValueLike> TypedPredicate<T>
Sourcepub fn new(predicate: Predicate) -> Self
pub fn new(predicate: Predicate) -> Self
Creates a new typed predicate from an untyped predicate
Sourcepub fn as_untyped(&self) -> &Predicate
pub fn as_untyped(&self) -> &Predicate
Returns a reference to the untyped Predicate wrapped by this
typed instance
Sourcepub fn check(&self, value: T) -> bool
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
Sourcepub fn always() -> Self
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);Sourcepub fn never() -> Self
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);Sourcepub fn and<P: Into<TypedPredicate<T>>, I: IntoIterator<Item = P>>(i: I) -> Self
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);Sourcepub fn not<P: Into<TypedPredicate<T>>>(p: P) -> Self
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);Sourcepub fn or<P: Into<TypedPredicate<T>>, I: IntoIterator<Item = P>>(i: I) -> Self
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);Sourcepub fn xor<P: Into<TypedPredicate<T>>, I: IntoIterator<Item = P>>(i: I) -> Self
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.
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.
Sourcepub fn any<P: Into<TypedPredicate<T>>>(p: P) -> Self
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);Sourcepub fn contains(value: T) -> Self
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);Sourcepub fn contains_all<I: IntoIterator<Item = T>>(i: I) -> Self
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);Sourcepub fn contains_any<I: IntoIterator<Item = T>>(i: I) -> Self
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>
impl<T: ValueLike> TypedPredicate<T>
Sourcepub fn equals(value: T) -> Self
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);Sourcepub fn greater_than(value: T) -> Self
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);Sourcepub fn greater_than_or_equals(value: T) -> Self
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);Sourcepub fn in_range(range: RangeInclusive<T>) -> Self
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);Sourcepub fn in_set<I: IntoIterator<Item = T>>(set: I) -> Self
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);Sourcepub fn less_than(value: T) -> Self
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);Sourcepub fn less_than_or_equals(value: T) -> Self
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);Sourcepub fn not_equals(value: T) -> Self
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);Sourcepub fn not_in_range(range: RangeInclusive<T>) -> Self
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);Sourcepub fn not_in_set<I: IntoIterator<Item = T>>(set: I) -> Self
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>>
impl<T: ValueLike> TypedPredicate<HashMap<String, T>>
Sourcepub fn has_key<K: Into<String>>(k: K) -> Self
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);Sourcepub fn has_key_where_value<K: Into<String>, P: Into<TypedPredicate<T>>>(
k: K,
p: P,
) -> Self
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>>
impl<T: ValueLike> TypedPredicate<Option<T>>
Sourcepub fn is_none() -> Self
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);Sourcepub fn not_none_and<P: Into<TypedPredicate<T>>>(p: P) -> Self
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);Sourcepub fn none_or<P: Into<TypedPredicate<T>>>(p: P) -> Self
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>
impl TypedPredicate<String>
Sourcepub fn text_ends_with<S: Into<String>>(s: S) -> Self
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);Sourcepub fn text_ends_with_case_insensitive<S: Into<String>>(s: S) -> Self
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);Sourcepub fn text_equals_case_insensitive<S: Into<String>>(s: S) -> Self
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);Sourcepub fn text_in_set_case_insensitive<S: Into<String>, I: IntoIterator<Item = S>>(
i: I,
) -> Self
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);Sourcepub fn text_not_equals_case_insensitive<S: Into<String>>(s: S) -> Self
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);Sourcepub fn text_starts_with<S: Into<String>>(s: S) -> Self
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);Sourcepub fn text_starts_with_case_insensitive<S: Into<String>>(s: S) -> Self
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);Sourcepub fn text_contained_in<S: Into<String>>(s: S) -> Self
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);Sourcepub fn text_contained_in_case_insensitive<S: Into<String>>(s: S) -> Self
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);Sourcepub fn text_contains_all<S: Into<String>, I: IntoIterator<Item = S>>(
i: I,
) -> Self
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);Sourcepub fn text_contains_all_case_insensitive<S: Into<String>, I: IntoIterator<Item = S>>(
i: I,
) -> Self
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);Sourcepub fn text_contains_any<S: Into<String>, I: IntoIterator<Item = S>>(
i: I,
) -> Self
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);Sourcepub fn text_contains_any_case_insensitive<S: Into<String>, I: IntoIterator<Item = S>>(
i: I,
) -> Self
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);Sourcepub fn text_ends_with_any<S: Into<String>, I: IntoIterator<Item = S>>(
i: I,
) -> Self
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);Sourcepub fn text_ends_with_any_case_insensitive<S: Into<String>, I: IntoIterator<Item = S>>(
i: I,
) -> Self
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);Sourcepub fn text_starts_with_any<S: Into<String>, I: IntoIterator<Item = S>>(
i: I,
) -> Self
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);Sourcepub fn text_starts_with_any_case_insensitive<S: Into<String>, I: IntoIterator<Item = S>>(
i: I,
) -> Self
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>
impl<T: ValueLike> BitAnd for TypedPredicate<T>
Source§fn bitand(self, rhs: Self) -> Self
fn bitand(self, rhs: Self) -> Self
Shorthand to produce Predicate::And
Source§type Output = TypedPredicate<T>
type Output = TypedPredicate<T>
& operator.Source§impl<T: ValueLike> BitOr for TypedPredicate<T>
impl<T: ValueLike> BitOr for TypedPredicate<T>
Source§fn bitor(self, rhs: Self) -> Self
fn bitor(self, rhs: Self) -> Self
Shorthand to produce Predicate::Or
Source§type Output = TypedPredicate<T>
type Output = TypedPredicate<T>
| operator.Source§impl<T: ValueLike> BitXor for TypedPredicate<T>
impl<T: ValueLike> BitXor for TypedPredicate<T>
Source§fn bitxor(self, rhs: Self) -> Self
fn bitxor(self, rhs: Self) -> Self
Shorthand to produce Predicate::Xor
Source§type Output = TypedPredicate<T>
type Output = TypedPredicate<T>
^ operator.Source§impl<T: Clone + ValueLike> Clone for TypedPredicate<T>
impl<T: Clone + ValueLike> Clone for TypedPredicate<T>
Source§fn clone(&self) -> TypedPredicate<T>
fn clone(&self) -> TypedPredicate<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: ValueLike, C: IntoIterator<Item = (String, T)> + ValueLike> From<MapTypedPredicate<T, C>> for TypedPredicate<C>
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
fn from(map_typed_predicate: MapTypedPredicate<T, C>) -> Self
Source§impl<T: ValueLike, C: IntoIterator<Item = (String, T)> + ValueLike> From<TypedPredicate<C>> for MapTypedPredicate<T, C>
impl<T: ValueLike, C: IntoIterator<Item = (String, T)> + ValueLike> From<TypedPredicate<C>> for MapTypedPredicate<T, C>
Source§fn from(typed_predicate: TypedPredicate<C>) -> Self
fn from(typed_predicate: TypedPredicate<C>) -> Self
Source§impl<T: ValueLike> From<TypedPredicate<T>> for Predicate
impl<T: ValueLike> From<TypedPredicate<T>> for Predicate
Source§fn from(typed_predicate: TypedPredicate<T>) -> Self
fn from(typed_predicate: TypedPredicate<T>) -> Self
Source§impl<T: ValueLike> Not for TypedPredicate<T>
impl<T: ValueLike> Not for TypedPredicate<T>
Source§fn not(self) -> Self::Output
fn not(self) -> Self::Output
Shorthand to produce Predicate::Not
Source§type Output = TypedPredicate<T>
type Output = TypedPredicate<T>
! operator.