Struct entity::MapTypedPredicate[][src]

pub struct MapTypedPredicate<T: ValueLike, C: IntoIterator<Item = (String, T)> + ValueLike>(_, _, _);

Represents a typed Predicate specifically for maps such as std::collections::HashMap, ensuring that only valid conditions are used for a given type.

This is required due to limitations in Rust’s blanket impl functionality, which will be resolved once specialization is available.

Implementations

impl<T: ValueLike, C: IntoIterator<Item = (String, T)> + ValueLike> MapTypedPredicate<T, C>[src]

pub fn new(predicate: Predicate) -> Self[src]

Creates a new map typed predicate from an untyped predicate

pub fn as_untyped(&self) -> &Predicate[src]

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

pub fn check(&self, value: C) -> bool[src]

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

impl<T: ValueLike, C: IntoIterator<Item = (String, T)> + ValueLike> MapTypedPredicate<T, C>[src]

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

Creates a new typed predicate for Predicate::Any

Examples

use entity::{TypedPredicate as P, MapTypedPredicate as MP};
use std::collections::HashMap;

let mut map = HashMap::new();
map.insert(String::from("a"), 1);
map.insert(String::from("b"), 2);
map.insert(String::from("c"), 3);

let p = MP::any(P::equals(3));
assert_eq!(p.check(map.clone()), true);

let p = MP::any(P::equals(4));
assert_eq!(p.check(map), false);

pub fn contains(value: T) -> Self[src]

Creates a new typed predicate for Predicate::Contains

Examples

use entity::{TypedPredicate as P, MapTypedPredicate as MP};
use std::collections::HashMap;

let mut map = HashMap::new();
map.insert(String::from("a"), 1);
map.insert(String::from("b"), 2);
map.insert(String::from("c"), 3);

let p = MP::contains(3);
assert_eq!(p.check(map.clone()), true);

let p = MP::contains(4);
assert_eq!(p.check(map), false);

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

Creates a new typed predicate for Predicate::ContainsAll

Examples

use entity::{TypedPredicate as P, MapTypedPredicate as MP};
use std::collections::HashMap;

let mut map = HashMap::new();
map.insert(String::from("a"), 1);
map.insert(String::from("b"), 2);
map.insert(String::from("c"), 3);

let p = MP::contains_all(vec![1, 3]);
assert_eq!(p.check(map.clone()), true);

let p = MP::contains_all(vec![1, 4]);
assert_eq!(p.check(map), false);

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

Creates a new typed predicate for Predicate::ContainsAny

Examples

use entity::{TypedPredicate as P, MapTypedPredicate as MP};
use std::collections::HashMap;

let mut map = HashMap::new();
map.insert(String::from("a"), 1);
map.insert(String::from("b"), 2);
map.insert(String::from("c"), 3);

let p = MP::contains_any(vec![1, 4]);
assert_eq!(p.check(map.clone()), true);

let p = MP::contains_any(vec![4, 5]);
assert_eq!(p.check(map), false);

Trait Implementations

impl<T: ValueLike, C: IntoIterator<Item = (String, T)> + ValueLike> BitAnd<MapTypedPredicate<T, C>> for MapTypedPredicate<T, C>[src]

type Output = Self

The resulting type after applying the & operator.

fn bitand(self, rhs: Self) -> Self[src]

Shorthand to produce Predicate::And

impl<T: ValueLike, C: IntoIterator<Item = (String, T)> + ValueLike> BitOr<MapTypedPredicate<T, C>> for MapTypedPredicate<T, C>[src]

type Output = Self

The resulting type after applying the | operator.

fn bitor(self, rhs: Self) -> Self[src]

Shorthand to produce Predicate::Or

impl<T: ValueLike, C: IntoIterator<Item = (String, T)> + ValueLike> BitXor<MapTypedPredicate<T, C>> for MapTypedPredicate<T, C>[src]

type Output = Self

The resulting type after applying the ^ operator.

fn bitxor(self, rhs: Self) -> Self[src]

Shorthand to produce Predicate::Xor

impl<T: Clone + ValueLike, C: Clone + IntoIterator<Item = (String, T)> + ValueLike> Clone for MapTypedPredicate<T, C>[src]

impl<T: Debug + ValueLike, C: Debug + IntoIterator<Item = (String, T)> + ValueLike> Debug for MapTypedPredicate<T, C>[src]

impl<T: ValueLike, C: IntoIterator<Item = (String, T)> + ValueLike> From<MapTypedPredicate<T, C>> for Predicate[src]

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

impl<T: ValueLike, C: IntoIterator<Item = (String, T)> + ValueLike> From<Predicate> for MapTypedPredicate<T, C>[src]

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

impl<T: ValueLike, C: IntoIterator<Item = (String, T)> + ValueLike> Not for MapTypedPredicate<T, C>[src]

type Output = Self

The resulting type after applying the ! operator.

fn not(self) -> Self::Output[src]

Shorthand to produce Predicate::Not

impl<T: PartialEq + ValueLike, C: PartialEq + IntoIterator<Item = (String, T)> + ValueLike> PartialEq<MapTypedPredicate<T, C>> for MapTypedPredicate<T, C>[src]

impl<T: ValueLike, C: IntoIterator<Item = (String, T)> + ValueLike> PartialEq<Predicate> for MapTypedPredicate<T, C>[src]

impl<T: ValueLike, C: IntoIterator<Item = (String, T)> + ValueLike> StructuralPartialEq for MapTypedPredicate<T, C>[src]

Auto Trait Implementations

impl<T, C> !RefUnwindSafe for MapTypedPredicate<T, C>

impl<T, C> !Send for MapTypedPredicate<T, C>

impl<T, C> !Sync for MapTypedPredicate<T, C>

impl<T, C> Unpin for MapTypedPredicate<T, C> where
    C: Unpin,
    T: Unpin

impl<T, C> !UnwindSafe for MapTypedPredicate<T, C>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DynClone for T where
    T: Clone
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.