forall T, 'k.
struct Vec! { ... }
A growable array that owns its heap block, under brand 'k.
alloc and back are restricted records held as fields: only Allocation!::adopt produces an Allocation! and only Region!::share a RegionResume!, so a Vec! holding them holds genuine ones. Since Vec! is not exposed, no foreign module can write the literal and pair an honest Ref with a stale record.
Methods
method try_newsource
fn try_new() -> Result[exists '1. (Exclusive!['1], Vec![T, '1]), AllocError] { ... }
An empty vec with capacity 4, under a fresh brand, or the allocation failure. Allocation!::adopt mints and seals the brand and records the block's base and extent; share trades the region for the Exclusive!/Ref pair this signature promises, plus the receipt that is the only route back. Growing it later aborts as push does.
method newsource
fn new() -> exists '1. (Exclusive!['1], Vec![T, '1]) { ... }
An empty vec under a fresh brand: try_new, aborting on failure.
method pushsource
fn push(self, tag: Exclusive!['k], val: T) -> exists '2. (Exclusive!['2], Vec![T, '2]) { ... }
Appends val, doubling the capacity when the vec is full. The only operation here where the storage can move. Always returns under a fresh brand, invalidating every descriptor of the old domain by type equality, growth or no growth.
The cycle, in the order the lines below run it:
back.resume(tag) consumes the caller's Exclusive!['k] and rebuilds the Region![T,'k]. resume demands the exact witness, of which there is one, so no other access capability of 'k is outstanding. alloc.release_storage(region) retires the domain into a raw Uninit! carrying the extent adopt recorded, so grow resizes a block whose size is the allocator's own number, never one re-derived here. HeapAllocator::grow only when full; otherwise the same Uninit! passes straight through. Allocation::adopt/share re-enter under a fresh brand, sealed by this function's exists '2..
On the non-growing path release_storage and adopt are Uninit! bookkeeping, with no malloc/free between them.
method lensource
fn len(&self) -> usize { ... }
How many elements the vec holds. The length is the vec's own field, not a read of its storage, so no capability is presented.
method is_emptysource
fn is_empty(&self) -> bool { ... }
Whether the vec holds no elements.
method get_refsource
fn get_ref(&self, &tag: Exclusive!['k], i: usize) -> Option[Ref[T, 'k]] { ... }
A Ref to element i, or None when i >= len. Checked against len, not cap: the slots between them are allocated but uninitialized, and a Ref into one would let Ref::copy read an uninitialized T.
method as_slicesource
fn as_slice(&self, &tag: Exclusive!['k]) -> Slice[T, 'k] { ... }
A checked view of every element, sharing the vec's live brand. tag is presented, never consumed: it proves the caller holds the current brand. A later push/pop returns a different brand, so the checker rejects any use of this Slice, or a Ref from it, against the vec's later state.
method popsource
fn pop(self, tag: Exclusive!['k]) -> exists '2. (Exclusive!['2], Vec![T, '2], Option[T]) { ... }
Removes and returns the last element, or None if the vec is empty. Rebrands like push, but never resizes the allocation.
method insertsource
fn insert(self, tag: Exclusive!['k], i: usize, val: T) -> exists '2. (Exclusive!['2], Vec![T, '2]) { ... }
Puts val at index i, moving the elements from i on one place up: push when i is the length. Stops the program (core::process::trap) when i is past the length. Rebrands as push does.
method removesource
fn remove(self, tag: Exclusive!['k], i: usize) -> exists '2. (Exclusive!['2], Vec![T, '2], Option[T]) { ... }
Takes the element at index i out, moving the ones after it one place down, or None when i is out of range. Rebrands as pop does.
method swapsource
fn swap(&self, &tag: Exclusive!['k], i: usize, j: usize) { ... }
Exchanges the elements at i and j; stops the program (core::process::trap) when either is out of range. Moves only, so any T, and no rebranding: a Ref to an index names what is there now.
method reversesource
fn reverse(&self, &tag: Exclusive!['k]) { ... }
Reverses the order of the elements, by moves, as swap does.
method destroy_withsource
fn destroy_with(self, tag: Exclusive!['k], f: fn(T) -> ()) -> () { ... }
Consumes the vec: calls f once per element (so a linear T can be consumed), then frees the buffer. f is a plain function pointer, not a capturing closure: it is called an unbounded number of times, and only a captureless fn is provably Copy generically. The address freed comes from alloc, recorded by Allocation!::adopt, not from buf.
method sort_unstable_bysource
forall Env where Copy[Env].
fn sort_unstable_by(&self, &tag: Exclusive!['k], cmp: closure[Env](T, T) -> (T, T, Order)) { ... }
Sorts the elements so cmp never says a later one orders before an earlier one. Not stable; any T.
method sort_unstablesource
fn sort_unstable(&self, &tag: Exclusive!['k]) { ... }
Sorts the elements in ascending Ord order. Not stable; any T.
method sort_bysource
forall C, Env where Copy[Env].
fn sort_by(&self, &tag: Exclusive!['k], &cx: C, cmp: closure[Env](&_: C, T, T) -> Order) { ... }
Sorts, stably, by cmp, which is lent the context cx for each comparison, so the order may read a domain the elements point into.
method sortsource
fn sort(&self, &tag: Exclusive!['k]) { ... }
Sorts the elements in ascending Ord order, stably.
method getsource
fn get(&self, &tag: Exclusive!['k], i: usize) -> Option[T] { ... }
A copy of element i, or None when it is out of range.
method atsource
fn at(&self, &tag: Exclusive!['k], i: usize) -> T { ... }
A copy of element i; stops the program (core::process::trap) when it is out of range. get is the form for an index that may miss.
method destroysource
fn destroy(self, tag: Exclusive!['k]) -> () { ... }
Frees a vector of Copy elements, which need no per-element callback.
method itersource
fn iter(self, tag: Exclusive!['k]) -> VecIter![T, 'k] { ... }
An iterator over the elements, holding the vec and its capability until VecIter!::finish hands them back.