forall T.
struct Owned! { ... }
Sole ownership of one heap-allocated T. Restricted, like everything in core::mem: only this module may construct or destructure these records.
Carries no brand: an Owned! is unshared, so there is nothing for a brand to witness. One appears when open splits it and goes away when close rejoins it. Carries no extent: the block's size is sizeof[T](), which new/try_new allocate and open recomputes, so the Owned! -> open -> close -> Owned! round trip is lossless without storing it. See Allocation!::close for the one narrowing direction.
Methods
method newsource
fn new(value: T) -> Owned![T] { ... }
Moves value into a new heap block. Aborts if allocation fails.
Not built on try_new: after abort() in a derived version, the Err arm would still have to produce an Owned![T] while holding try_new's returned T, which it can neither store (there is no allocation) nor drop (T may be linear). HeapAllocator::grow can be layered because its error arm hands back an Uninit!, the very thing it returns. So new calls HeapAllocator::alloc directly.
method try_newsource
fn try_new(value: T) -> Result[Owned![T], (AllocError, T)] { ... }
Moves value into a new heap block, or hands it back with the allocation failure.
The fallible constructor. The error arm hands value back unmoved, so a linear T survives an allocation failure and the caller must decide what happens to it.
method updatesource
forall Ret.
fn update(&self, f: closure(&_: T) -> Ret) -> Ret { ... }
Calls f on the owned value where it lives: f gets it through &, and nothing is copied out or back. Holding self is the only access to the value, so nothing else reads or writes it while f runs.
method update_insource
forall C, Ret.
fn update_in(&self, &cx: C, f: closure(&_: T, &_: C) -> Ret) -> Ret { ... }
update, with a context cx lent to f beside the value.
method into_valuesource
fn into_value(self) -> T { ... }
Frees the allocation and returns the contained T. Freeing the storage does not consume what is in it: a linear T (a nested Owned!, say) must go back to the caller rather than be dropped.
method opensource
fn open(self) -> exists '1. (Allocation![T, '1], Region![T, '1]) { ... }
Splits sole ownership into a freshly branded pair: the right to free (Allocation!) and the right to access (Region!). Allocation!::close is the exact inverse and the only way back to an Owned![T].
Goes through Allocation!::adopt so there is one place an allocation record is created. adopt_raw_sized's precondition holds: p is the base of a single live block allocated by new/try_new; self was consumed above, so no other owner exists; and sizeof[T]() is exactly the size they requested.