Skip to main content

Predicate

Trait Predicate 

Source
pub trait Predicate {
    type Subject;

    // Required method
    fn check<'life0, 'async_trait>(
        &'life0 self,
        subject: Self::Subject,
    ) -> Pin<Box<dyn Future<Output = PredicateResult<Self::Subject>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Trait for evaluating whether a subject should be cached.

Predicates are the core abstraction for cache decision logic. They are protocol-agnostic - the same trait works for HTTP requests, gRPC messages, or any other protocol type.

§Type Parameters

The Subject associated type defines what this predicate evaluates. For request predicates, this is typically a request type. For response predicates, this is typically a response type.

§Ownership

The check method takes ownership of the subject and returns it wrapped in a PredicateResult. This allows the subject to flow through a chain of predicates without cloning.

Required Associated Types§

Source

type Subject

The type being evaluated by this predicate.

Required Methods§

Source

fn check<'life0, 'async_trait>( &'life0 self, subject: Self::Subject, ) -> Pin<Box<dyn Future<Output = PredicateResult<Self::Subject>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Evaluate whether the subject should be cached.

Returns PredicateResult::Cacheable if the subject should be cached, or PredicateResult::NonCacheable if it should bypass the cache.

Implementations on Foreign Types§

Source§

impl<T> Predicate for &T
where T: Predicate + ?Sized + Sync, T::Subject: Send,

Source§

type Subject = <T as Predicate>::Subject

Source§

fn check<'life0, 'async_trait>( &'life0 self, subject: T::Subject, ) -> Pin<Box<dyn Future<Output = PredicateResult<T::Subject>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

impl<T> Predicate for Box<T>
where T: Predicate + ?Sized + Sync, T::Subject: Send,

Source§

type Subject = <T as Predicate>::Subject

Source§

fn check<'life0, 'async_trait>( &'life0 self, subject: T::Subject, ) -> Pin<Box<dyn Future<Output = PredicateResult<T::Subject>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

impl<T> Predicate for Arc<T>
where T: Predicate + Send + Sync + ?Sized, T::Subject: Send,

Source§

type Subject = <T as Predicate>::Subject

Source§

fn check<'life0, 'async_trait>( &'life0 self, subject: T::Subject, ) -> Pin<Box<dyn Future<Output = PredicateResult<T::Subject>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Implementors§

Source§

impl<L, R> Predicate for And<L, R>
where L: Predicate + Send + Sync, R: Predicate<Subject = L::Subject> + Send + Sync, L::Subject: Send,

Source§

impl<L, R> Predicate for Or<L, R>
where L: Predicate + Send + Sync, R: Predicate<Subject = L::Subject> + Send + Sync, L::Subject: Send,

Source§

impl<P> Predicate for Not<P>
where P: Predicate + Send + Sync, P::Subject: Send,

Source§

impl<S> Predicate for Neutral<S>
where S: Send,