Skip to main content

EvaluationContext

Struct EvaluationContext 

Source
pub struct EvaluationContext<UserData> { /* private fields */ }
Expand description

Immutable input data for specifications that need counters, flags, time, and application-specific user data.

The context has no interior mutability or global registration mechanism. It is Send and Sync when UserData and its standard-library fields are, allowing callers to move or share a context according to the auto-trait rules of the user data they provide.

Implementations§

Source§

impl<UserData> EvaluationContext<UserData>

Source

pub fn new(user_data: UserData) -> Self

Creates an empty context containing typed user_data.

Source

pub fn with_counter(self, key: impl Into<String>, value: u64) -> Self

Adds or replaces a counter while constructing the context.

Source

pub fn with_flag(self, key: impl Into<String>, value: bool) -> Self

Adds or replaces a flag while constructing the context.

Source

pub fn with_timestamp(self, key: impl Into<String>, value: Duration) -> Self

Adds or replaces a timestamp while constructing the context.

Source

pub fn user_data(&self) -> &UserData

Returns the typed application data.

Source

pub fn counter(&self, key: &str) -> u64

Returns a counter, treating a missing key as zero.

Source

pub fn flag(&self, key: &str) -> bool

Returns a flag, treating a missing key as false.

Source

pub fn timestamp(&self, key: &str) -> Option<Duration>

Returns the timestamp stored for key, if one exists.

Trait Implementations§

Source§

impl<UserData> Specification<EvaluationContext<UserData>> for MaxCount

Source§

fn is_satisfied_by(&self, context: &EvaluationContext<UserData>) -> bool

Returns whether candidate satisfies this rule.
Source§

fn and<Other>(self, other: Other) -> And<Self, Other>
where Self: Sized, Other: Specification<T>,

Combines this rule with other using short-circuiting logical AND. Read more
Source§

fn or<Other>(self, other: Other) -> Or<Self, Other>
where Self: Sized, Other: Specification<T>,

Combines this rule with other using short-circuiting logical OR. Read more
Source§

fn not(self) -> Not<Self>
where Self: Sized,

Creates a rule that negates this rule’s result.
Source§

impl<UserData> Specification<EvaluationContext<UserData>> for Flag

Source§

fn is_satisfied_by(&self, context: &EvaluationContext<UserData>) -> bool

Returns whether candidate satisfies this rule.
Source§

fn and<Other>(self, other: Other) -> And<Self, Other>
where Self: Sized, Other: Specification<T>,

Combines this rule with other using short-circuiting logical AND. Read more
Source§

fn or<Other>(self, other: Other) -> Or<Self, Other>
where Self: Sized, Other: Specification<T>,

Combines this rule with other using short-circuiting logical OR. Read more
Source§

fn not(self) -> Not<Self>
where Self: Sized,

Creates a rule that negates this rule’s result.
Source§

impl<UserData, ClockType> Specification<EvaluationContext<UserData>> for Cooldown<ClockType>
where ClockType: Clock,

Source§

fn is_satisfied_by(&self, context: &EvaluationContext<UserData>) -> bool

Returns whether candidate satisfies this rule.
Source§

fn and<Other>(self, other: Other) -> And<Self, Other>
where Self: Sized, Other: Specification<T>,

Combines this rule with other using short-circuiting logical AND. Read more
Source§

fn or<Other>(self, other: Other) -> Or<Self, Other>
where Self: Sized, Other: Specification<T>,

Combines this rule with other using short-circuiting logical OR. Read more
Source§

fn not(self) -> Not<Self>
where Self: Sized,

Creates a rule that negates this rule’s result.

Auto Trait Implementations§

§

impl<UserData> Freeze for EvaluationContext<UserData>
where UserData: Freeze,

§

impl<UserData> RefUnwindSafe for EvaluationContext<UserData>
where UserData: RefUnwindSafe,

§

impl<UserData> Send for EvaluationContext<UserData>
where UserData: Send,

§

impl<UserData> Sync for EvaluationContext<UserData>
where UserData: Sync,

§

impl<UserData> Unpin for EvaluationContext<UserData>
where UserData: Unpin,

§

impl<UserData> UnsafeUnpin for EvaluationContext<UserData>
where UserData: UnsafeUnpin,

§

impl<UserData> UnwindSafe for EvaluationContext<UserData>
where UserData: UnwindSafe,

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> 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> 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, 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.