Struct mucell::MuCellStable [-]  [+] [src]

pub struct MuCell<T> {
    // some fields omitted
}

A cell with the ability to mutate the value through an immutable reference when safe

Methods

impl<T> MuCell<T>

fn new(value: T) -> MuCell<T>

Construct a new cell containing the given value

fn borrow_mut(&mut self) -> &mut T

Borrow the contained object mutably.

This is genuinely and completely free.

fn borrow(&self) -> Ref<T>

Borrow the contained object immutably.

Unlike borrow_mut, this isn’t quite free, but oh, so all but! It has a smattering of reference counting. No branches, though, so it’s as fast as is computationally possible.

fn try_mutate<F: FnOnce(&mut T)>(&self, mutator: F) -> bool

Mutate the contained object if possible.

If any immutable references produced by calling borrow() are active, this will return false, not executing the function given.

If there are no immutable references active, this will execute the mutator function and return true.

Caution: you should avoid touching self inside the mutator (not that it would really make much sense to be touching it, anyway); most notably, you MUST NOT call borrow on self inside the mutator, which includes things like the == implementation which borrow the value briefly; while calling try_mutate inside it will just return false, in debug builds calling borrow will panic and in release builds it will break memory safety as you will have both a mutable and an immutable reference to the same object at the same time (yep, it’s not quite preventing aliasing). So don’t do it.

Trait Implementations

impl<T: PartialEq> PartialEq for MuCell<T>

fn eq(&self, other: &MuCell<T>) -> bool

fn ne(&self, other: &Rhs) -> bool

impl<T: Eq> Eq for MuCell<T>

fn assert_receiver_is_total_eq(&self)

impl<T: PartialOrd> PartialOrd for MuCell<T>

fn partial_cmp(&self, other: &MuCell<T>) -> Option<Ordering>

fn lt(&self, other: &Rhs) -> bool

fn le(&self, other: &Rhs) -> bool

fn gt(&self, other: &Rhs) -> bool

fn ge(&self, other: &Rhs) -> bool

impl<T: Ord> Ord for MuCell<T>

fn cmp(&self, other: &MuCell<T>) -> Ordering

impl<T: Default> Default for MuCell<T>

fn default() -> MuCell<T>

impl<T: Clone> Clone for MuCell<T>

fn clone(&self) -> MuCell<T>

fn clone_from(&mut self, source: &Self)

impl<T: Show> Show for MuCell<T>

fn fmt(&self, f: &mut Formatter) -> Result

impl<T: Octal> Octal for MuCell<T>

fn fmt(&self, f: &mut Formatter) -> Result

impl<T: Binary> Binary for MuCell<T>

fn fmt(&self, f: &mut Formatter) -> Result

impl<T: LowerHex> LowerHex for MuCell<T>

fn fmt(&self, f: &mut Formatter) -> Result

impl<T: UpperHex> UpperHex for MuCell<T>

fn fmt(&self, f: &mut Formatter) -> Result

impl<T: Pointer> Pointer for MuCell<T>

fn fmt(&self, f: &mut Formatter) -> Result

impl<T: LowerExp> LowerExp for MuCell<T>

fn fmt(&self, f: &mut Formatter) -> Result

impl<T: UpperExp> UpperExp for MuCell<T>

fn fmt(&self, f: &mut Formatter) -> Result

impl<T: Rand> Rand for MuCell<T>

fn rand<R: Rng>(rng: &mut R) -> MuCell<T>

impl<H, T> Hash<H> for MuCell<T> where H: Hasher, T: Hash<H>

fn hash(&self, state: &mut H)