stdlib.cell¶
Interior Mutability (Cell + RefCell)
Generated from
v0.60.1. 1 source files, 20 documented symbols.
cell.xi¶
type Cell¶
Cell -- simple interior mutability via unsafe pointer casts
| Field | Type |
|---|---|
value |
T |
fn new[T](value: T) -> Cell[T]¶
Create a new cell holding
value.
fn get[T](self: Self) -> T¶
Copy the current value out.
fn set[T](self: Self, value: T)¶
Replace the stored value.
fn replace[T](self: Self, value: T) -> T¶
Replace the stored value, returning the previous one.
- Postcondition:
result == value@pre
fn swap[T](self: Self, other: &mut Cell[T])¶
Swap the values of two cells.
- Postcondition:
value == other.value@pre
type RefCell¶
borrows > 0: active shared borrows borrows == -1: one active mutable borrow borrows == 0: no active borrows
| Field | Type |
|---|---|
value |
T |
borrows |
Int |
Invariants:
- borrows >= -1
type Ref¶
6D.1: Ref holds a raw pointer to the ORIGINAL RefCell, not a copy.
| Field | Type |
|---|---|
ptr |
*RefCell[T] |
type RefMut¶
6D.1: RefMut holds a raw pointer to the ORIGINAL RefCell.
| Field | Type |
|---|---|
ptr |
*RefCell[T] |
fn new[T](value: T) -> RefCell[T]¶
Create a new RefCell holding
value.
- Postcondition:
borrows == 0
fn borrow[T](self: Self) -> Ref[T]¶
Shared borrow; aborts when a mutable borrow is active.
- Precondition:
borrows >= 0
fn borrow_mut[T](self: Self) -> RefMut[T]¶
Exclusive borrow; aborts when any borrow is active.
- Precondition:
borrows == 0
fn try_borrow[T](self: Self) -> Option[Ref[T]]¶
Shared borrow, or None when a mutable borrow is active.
- Precondition:
true
fn try_borrow_mut[T](self: Self) -> Option[RefMut[T]]¶
Exclusive borrow, or None when any borrow is active.
- Precondition:
true
fn replace[T](self: Self, value: T) -> T¶
Replace the value, returning the previous one.
- Precondition:
true - Postcondition:
result == value@pre
fn release[T](self: Self)¶
Release the shared borrow. Must be called when done with the Ref. Without Drop trait support, the user is responsible for calling this.
- Precondition:
true
fn get[T](self: Self) -> T¶
Get the CURRENT value from the RefCell (not a stale copy).
- Precondition:
ptr != null
fn release[T](self: Self)¶
Release the mutable borrow. Restores borrows from -1 to 0.
- Precondition:
true
fn get[T](self: Self) -> T¶
Get the current value. Returns by value (XIOM limitation: no &T references yet).
- Precondition:
ptr != null
fn set[T](self: Self, value: T)¶
Set a new value through the mutable borrow.
- Precondition:
ptr != null