MapTypedPredicate

Struct MapTypedPredicate 

Source
pub struct MapTypedPredicate<T: ValueLike, C: IntoIterator<Item = (String, T)> + ValueLike>(/* private fields */);
Expand description

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§

Source§

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

Source

pub fn new(predicate: Predicate) -> Self

Creates a new map 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: C) -> 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§

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

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, 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);
Source

pub fn contains(value: T) -> Self

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);
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, 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);
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, 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§

Source§

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

Source§

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

Shorthand to produce Predicate::And

Source§

type Output = MapTypedPredicate<T, C>

The resulting type after applying the & operator.
Source§

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

Source§

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

Shorthand to produce Predicate::Or

Source§

type Output = MapTypedPredicate<T, C>

The resulting type after applying the | operator.
Source§

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

Source§

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

Shorthand to produce Predicate::Xor

Source§

type Output = MapTypedPredicate<T, C>

The resulting type after applying the ^ operator.
Source§

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

Source§

fn clone(&self) -> MapTypedPredicate<T, C>

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, C: Debug + IntoIterator<Item = (String, T)> + ValueLike> Debug for MapTypedPredicate<T, C>

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 Predicate

Source§

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

Converts to this type from the input type.
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, C: IntoIterator<Item = (String, T)> + ValueLike> From<Predicate> for MapTypedPredicate<T, C>

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, C: IntoIterator<Item = (String, T)> + ValueLike> Not for MapTypedPredicate<T, C>

Source§

fn not(self) -> Self::Output

Shorthand to produce Predicate::Not

Source§

type Output = MapTypedPredicate<T, C>

The resulting type after applying the ! operator.
Source§

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

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: PartialEq + ValueLike, C: PartialEq + IntoIterator<Item = (String, T)> + ValueLike> PartialEq for MapTypedPredicate<T, C>

Source§

fn eq(&self, other: &MapTypedPredicate<T, C>) -> 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, C: IntoIterator<Item = (String, T)> + ValueLike> StructuralPartialEq for MapTypedPredicate<T, C>

Auto Trait Implementations§

§

impl<T, C> Freeze for MapTypedPredicate<T, C>

§

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 T: Unpin, C: Unpin,

§

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

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.