Struct mucell::MuCell
[−]
[src]
pub struct MuCell<T: ?Sized> { // some fields omitted }
A cell with the ability to mutate the value through an immutable reference when safe.
Methods
impl<T> MuCell<T>[src]
fn new(value: T) -> MuCell<T>
fn into_inner(self) -> T
Consumes the MuCell, returning the wrapped value.
Examples
use mucell::MuCell; let c = MuCell::new(5); let five = c.into_inner();
impl<T: ?Sized> MuCell<T>[src]
fn borrow(&self) -> Ref<&T>
Immutably borrows the wrapped value.
The borrow lasts until the returned Ref exits scope.
Multiple immutable borrows can be taken out at the same time.
Panics
Panics if called inside the try_mutate() mutator function.
But that’s generally a nonsensical thing to do, anyway, so just be sensible and you’re OK.
fn borrow_mut(&mut self) -> &mut T
Mutably borrows the wrapped value.
Unlike RefCell.borrow_mut, this method lets Rust’s type system prevent aliasing
and so cannot have anything go wrong. It is also, in consequence, completely free,
unlike RefCell or MuCell.borrow which all have to keep track of borrows at runtime.
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.
The mutator function should not touch self (not that it would really
make much sense to be touching it, anyway); most notably, you may 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, calling
borrow will panic.
Trait Implementations
impl<T: ?Sized> Send for MuCell<T> where T: Send[src]
impl<T: ?Sized + PartialEq> PartialEq for MuCell<T>[src]
fn eq(&self, other: &MuCell<T>) -> bool
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Rhs) -> bool1.0.0
This method tests for !=.
impl<T: ?Sized + Eq> Eq for MuCell<T>[src]
impl<T: PartialOrd> PartialOrd for MuCell<T>[src]
fn partial_cmp(&self, other: &MuCell<T>) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool1.0.0
This method tests less than (for self and other) and is used by the < operator. Read more
fn le(&self, other: &Rhs) -> bool1.0.0
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
fn gt(&self, other: &Rhs) -> bool1.0.0
This method tests greater than (for self and other) and is used by the > operator. Read more
fn ge(&self, other: &Rhs) -> bool1.0.0
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
impl<T: Ord> Ord for MuCell<T>[src]
fn cmp(&self, other: &MuCell<T>) -> Ordering
This method returns an Ordering between self and other. Read more
impl<T: Default> Default for MuCell<T>[src]
impl<T: Clone> Clone for MuCell<T>[src]
fn clone(&self) -> MuCell<T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0
Performs copy-assignment from source. Read more
impl<T: Display> Display for MuCell<T>[src]
impl<T: Debug> Debug for MuCell<T>[src]
impl<T: Octal> Octal for MuCell<T>[src]
impl<T: LowerHex> LowerHex for MuCell<T>[src]
impl<T: UpperHex> UpperHex for MuCell<T>[src]
impl<T: Pointer> Pointer for MuCell<T>[src]
impl<T: Binary> Binary for MuCell<T>[src]
impl<T: LowerExp> LowerExp for MuCell<T>[src]
impl<T: UpperExp> UpperExp for MuCell<T>[src]
impl<T> Hash for MuCell<T> where T: Hash[src]
fn hash<H: Hasher>(&self, state: &mut H)
Feeds this value into the state given, updating the hasher as necessary.
fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher1.3.0
Feeds a slice of this type into the state provided.