std/alloc
Types
Arena
pub type Arena
Arena allocator: everything allocated in its scope is freed together when the scope ends.
Arena.create
pub fn Arena.create() -> AllocatorHandle!
Creates an arena; fails when the host cannot provide memory.
Arena.tryCreate
pub fn Arena.tryCreate() -> Result[AllocatorHandle, AllocError]
Creates an arena, reporting a refused allocation as AllocError.
AllocatorHandle
pub type AllocatorHandle
Handle to an allocator, obtained from Arena.create(); scope() makes it current. It counts references non-atomically, so it is neither Send nor Sync.
AllocatorHandle.scope
pub noalloc fn AllocatorHandle.scope(self) -> AllocatorScope
Scope that makes this allocator current inside an allocator block; its bookkeeping lives in this allocator, so no ambient allocator is needed.
AllocatorHandle.allocated
pub fn AllocatorHandle.allocated(self) -> Int
Bytes handed out by this allocator so far; the VM reports 0.
AllocatorScope
pub type AllocatorScope
Value consumed by an allocator ... { } block to route its allocations.
Shared
pub type Shared[T]
Reference-counted shared ownership of a T within one thread: every clone is the same cell, and set replaces its value. It is neither Send nor Sync.
Shared.new
pub fn Shared.new[T](value: T) -> Shared[T]
Wraps a value in a shared cell.
Shared.tryNew
pub fn Shared.tryNew[T](value: T) -> Result[Shared[T], AllocError]
Wraps a value in a shared cell, or AllocError when the allocator refuses (new panics instead).
Shared.clone
pub fn Shared[T].clone(self) -> Shared[T]
Another handle to the same cell.
Shared.get
pub fn Shared[T: Copy].get(self) -> T
A copy of the current content.
Shared.tryGet
pub fn Shared[T: Copy].tryGet(self) -> Result[T, AllocError]
A copy of the current content, or AllocError when the allocator refuses (get panics instead).
Shared.set
pub fn Shared[T].set(self, value: T)
Replaces the content; the old value is dropped. Panics while a with or withMut of the same cell is running.
Shared.with
pub fn Shared[T].with[R](self, f: fn(&T) -> R) -> R
Calls f once with a borrow of the content and returns what it returns; f is not kept (non-escaping). Panics on reentrant withMut into the same cell.
Shared.withMut
pub fn Shared[T].withMut[R](self, f: fn(&mut T) -> R) -> R
Calls f once with an exclusive borrow of the content, so f can mutate it in place; f is not kept. Panics on reentrant with/withMut into the same cell.
Shared.downgrade
pub fn Shared[T].downgrade(self) -> Weak[T]
A weak handle to the same cell.
Shared.tryDowngrade
pub fn Shared[T].tryDowngrade(self) -> Result[Weak[T], AllocError]
A weak handle to the same cell, or AllocError when the allocator refuses (downgrade panics instead).
Weak
pub type Weak[T]
Non-owning handle to a Shared cell; it breaks reference cycles.
Weak.upgrade
pub fn Weak[T].upgrade(self) -> Shared[T]?
The cell as a Shared while some Shared still owns it; None once the last one was dropped.
Weak.clone
pub fn Weak[T].clone(self) -> Weak[T]
Another weak handle to the same cell.
Box
@unsafeGuarantee(Send when T: Send, Sync when T: Sync)
pub type Box[T]
Owned heap cell holding one T: exactly one owner, never copied implicitly, and how a type refers to itself (Wrap(kid: Box[Node])). Safety: a Box is the only owner of its T, so sending it moves T and sharing it only shares T.
Box.new
pub pure fn Box.new[T](value: T) -> Box[T]
Moves value onto the heap.
Box.tryNew
pub pure fn Box.tryNew[T](value: T) -> Result[Box[T], AllocError]
Moves value onto the heap, or AllocError when the allocator refuses (new panics instead).
Box.get
pub pure noalloc fn Box[T: Copy].get(self) -> T
A copy of the current content.
Box.set
pub pure fn Box[T].set(mut self, value: T)
Replaces the content; the old value is dropped.
Box.with
pub pure noalloc fn Box[T].with[R](self, f: fn(&T) -> R) -> R
Calls f once with a borrow of the content and returns what it returns; f is not kept (non-escaping).
Box.withMut
pub pure noalloc fn Box[T].withMut[R](mut self, f: fn(&mut T) -> R) -> R
Calls f once with an exclusive borrow of the content, so f can mutate it in place; f is not kept.
Box.into
pub pure noalloc fn Box[T].into(move self) -> T
Moves the content out and frees the cell; the only way to take ownership of the content back.
Box.equals
pub pure fn Box[T: Eq].equals(self, other: &Box[T]) -> Bool
Equality of the contents; satisfies Eq when T does.
Box.hash
pub pure fn Box[T: Hash].hash(self) -> u64
The hash of the content; satisfies Hash when T does.
Box.compareTo
pub pure fn Box[T: Ord].compareTo(self, other: &Box[T]) -> Ordering
Order of the contents; satisfies Ord when T does.
Box.display
pub pure fn Box[T: Display].display(self) -> String
The text of the content; satisfies Display when T does.