[][src]Trait r_fairdist::counter::Counter

pub trait Counter {
    type Index: Clone + Ord;
    type Scalar: Scalar;
    fn from_template(template: &Self) -> Self;
fn slot(&mut self, index: &Self::Index) -> &mut Self::Scalar;
fn empty(&self) -> bool; }

Multi-dimensional resource counter

This trait represents a set of resource counters that can be indexed to access the individual scalar counters. In its simplest form it can be thought of as an array of scalar counters, but more complex setups are possible.

A resource counter needs to select the index used to access the individual slots, the scalar type that each slot uses, as well as a function to replicate itself.

Associated Types

type Index: Clone + Ord

type Scalar: Scalar

Loading content...

Required methods

fn from_template(template: &Self) -> Self

Create new counter from a template.

This takes an existing counter as a template and creates a new counter that has the same dimensions. The new counter is initialized to zero. That is, the template is only used to make sure both counters have the same amount of slots.

fn slot(&mut self, index: &Self::Index) -> &mut Self::Scalar

Dereference an individual slot on the counter.

This function returns a mutable reference to the slot with index [index]. It is similar to an implementation of [std::ops::IndexMut], but takes a reference as index.

fn empty(&self) -> bool

Check whether the counter is empty.

This checks all slots of the counter whether they are empty. If all are empty (that is, they are 0, as in num::Zero::is_zero()), this will return true, otherwise false is returned.

Loading content...

Implementations on Foreign Types

impl<S> Counter for [S; 1] where
    S: Scalar
[src]

type Index = ()

type Scalar = S

impl<S> Counter for Box<[S]> where
    S: Scalar
[src]

type Index = usize

type Scalar = S

Loading content...

Implementors

Loading content...