pub struct RcIncr(/* private fields */);
Expand description
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);
}
Implementations§
Trait Implementations§
source§impl PartialEq<RcIncr> for RcIncr
impl PartialEq<RcIncr> for RcIncr
source§impl PartialOrd<RcIncr> for RcIncr
impl PartialOrd<RcIncr> for RcIncr
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl Eq for RcIncr
impl StructuralEq for RcIncr
impl StructuralPartialEq for RcIncr
Auto Trait Implementations§
impl !RefUnwindSafe for RcIncr
impl !Send for RcIncr
impl !Sync for RcIncr
impl Unpin for RcIncr
impl !UnwindSafe for RcIncr
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more