Struct incr::RcIncr[][src]

pub struct RcIncr(_);

The Rc<Cell<_>> backed storage of RcIncr provides flexibility in situations where the counter must be shared among several disparate objects/contexts while retaining consistentcy between all the references of the count. RcIncr is not threadsafe, and even in single-threaded code Rc<Cell<T>> has some tricky edge cases, for instance if a Cell<T> is used as the key to a hash map and the interior value mutated (fair warning).

Examples

use incr::RcIncr;
let mut last = RcIncr::default();
assert_eq!(last.is_new(1), true);
let mut xs = Vec::new();
for i in 2..5 {
    xs.push(last.clone());
    xs.last().unwrap().is_new(i);
}
assert_eq!(last.get(), 4);
for x in &xs {
    assert_eq!(x.get(), 4);
}

Methods

impl RcIncr
[src]

Returns true if val is greater than the highest previously observed value. If val is a new maximum, it is stored in self for checks against future values subsequent calls Self::get(&self) will return val until a new max is observed.

Returns the current value of self, which is the maximum observed value.

Trait Implementations

impl Default for RcIncr
[src]

Returns the "default value" for a type. Read more

impl Clone for RcIncr
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl PartialEq for RcIncr
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialOrd for RcIncr
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl Eq for RcIncr
[src]

impl Debug for RcIncr
[src]

Formats the value using the given formatter. Read more

impl From<u64> for RcIncr
[src]

Performs the conversion.

Auto Trait Implementations

impl !Send for RcIncr

impl !Sync for RcIncr