pub struct MapCell<T> { /* private fields */ }
Expand description

A mutable memory location that enforces borrow rules at runtime without possible panics.

A MapCell is a potential reference to mutable memory. Borrow rules are enforced by forcing clients to either move the memory out of the cell or operate on a borrow within a closure. You can think of a MapCell as an Option wrapped in a RefCell — attempts to take the value from inside a MapCell may fail by returning None.

Implementations

Creates an empty MapCell

Creates a new MapCell containing value

Returns a boolean which indicates if the MapCell is unoccupied.

Returns a boolean which indicates if the MapCell is occupied.

Takes the value out of the MapCell leaving it empty. If the value has already been taken elsewhere (and not replaceed), the returned Option will be None.

Examples
extern crate tock_cells;
use tock_cells::map_cell::MapCell;

let cell = MapCell::new(1234);
let x = &cell;
let y = &cell;

assert_eq!(x.take(), Some(1234));
assert_eq!(y.take(), None);

Puts a value into the MapCell.

Replaces the contents of the MapCell with val. If the cell was not empty, the previous value is returned, otherwise None is returned.

Allows closure to borrow the contents of the MapCell if-and-only-if it is not taken already. The state of the MapCell is unchanged after the closure completes.

Examples
extern crate tock_cells;
use tock_cells::map_cell::MapCell;

let cell = MapCell::new(1234);
let x = &cell;
let y = &cell;

x.map(|value| {
    // We have mutable access to the value while in the closure
    *value += 1;
});

// After the closure completes, the mutable memory is still in the cell,
// but potentially changed.
assert_eq!(y.take(), Some(1235));

Behaves the same as map, except the closure is allowed to return an Option.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.