Trait Rule

Source
pub trait Rule<T>
where T: Clone,
{ // Required methods fn score(&self, item: &T, bucket: &Bucket<T>) -> Scalar; fn box_clone(&self) -> Box<dyn Rule<T>>; }
Expand description

Trait used to tell how much successfuly bucket has to get incoming item.

§Example

use psyche_utils::bucket_strainer::{Bucket, Rule};
use psyche_utils::Scalar;

#[derive(Clone)]
struct SuccessRule;

impl<T> Rule<T> for SuccessRule
where
    T: Clone,
{
    fn score(&self, _: &T, _: &Bucket<T>) -> Scalar {
        1.0
    }

    fn box_clone(&self) -> Box<dyn Rule<T>> {
        Box::new((*self).clone())
    }
}

Required Methods§

Source

fn score(&self, item: &T, bucket: &Bucket<T>) -> Scalar

Score incoming item.

§Arguments
  • item - Incoming item.
  • bucket - Bucket that tests incoming item.
§Return

Score for given item that tell how lucky it is to fall into given bucket.

Source

fn box_clone(&self) -> Box<dyn Rule<T>>

Create boxed clone for this rule.

Trait Implementations§

Source§

impl<T> Clone for Box<dyn Rule<T>>
where T: Clone,

Source§

fn clone(&self) -> Box<dyn Rule<T>>

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

Implementors§

Source§

impl<T> Rule<T> for BucketLimitRule
where T: Clone,

Source§

impl<T> Rule<T> for ClosureRule<T>
where T: Clone + 'static,

Source§

impl<T> Rule<T> for FixedScoreRule
where T: Clone,

Source§

impl<T> Rule<T> for MulRule<T>
where T: Clone + 'static,

Source§

impl<T> Rule<T> for SumRule<T>
where T: Clone + 'static,