Struct

alloc::collections::vec::OwnedVec!

source
forall T.
exposed struct OwnedVec! {
    inner: exists 'k. (Exclusive!['k], Vec![T, 'k]),
}

A Vec! packaged with its capability, for a vector kept across calls or in a loop variable without naming its brand. Each method opens the package, calls the Vec! method and repacks the result under whatever brand it returned, so a growing vector needs no let exists/pack at the call site. inner is the package itself: open it for the branded API, such as get_ref or as_slice, and pack it back afterwards.

Methods

method newsource

fn new() -> OwnedVec![T] { ... }

An empty vector, aborting when allocation fails.

method try_newsource

fn try_new() -> Result[OwnedVec![T], AllocError] { ... }

An empty vector, or the allocation failure: Vec!::try_new's vec, packaged.

method lensource

fn len(&self) -> usize { ... }

How many elements the vector holds.

method is_emptysource

fn is_empty(&self) -> bool { ... }

Whether the vector holds no elements.

method pushsource

fn push(&self, val: T) { ... }

Adds val at the end.

method popsource

fn pop(&self) -> Option[T] { ... }

Removes the last element and hands it back, or None when there is none.

method insertsource

fn insert(&self, i: usize, val: T) { ... }

Puts val at index i, moving the elements from i on one place up; stops the program when i is past the length (Vec!::insert).

method removesource

fn remove(&self, i: usize) -> 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 (Vec!::remove).

method swapsource

fn swap(&self, i: usize, j: usize) { ... }

Exchanges the elements at i and j; stops the program when either is out of range (Vec!::swap).

method reversesource

fn reverse(&self) { ... }

Reverses the order of the elements (Vec!::reverse).

method withsource

forall Ret, Env where Copy[Env].
fn with(&self, i: usize, f: closure[Env](T) -> (T, Ret)) -> Option[Ret] { ... }

Calls f on element i in place: f takes the element and hands it back with a result. None when i is out of range, in which case f is dropped uncalled, so what it captures must be Copy.

method updatesource

forall Ret, Env where Copy[Env].
fn update(&self, i: usize, f: closure[Env](&_: T) -> Ret) -> Option[Ret] { ... }

Calls f on element i where it lives: f gets it through &, and nothing is copied out or back. None when i is out of range, in which case f is dropped uncalled, so what it captures must be Copy.

method update_insource

forall C, Ret, Env where Copy[Env].
fn update_in(&self, i: usize, &cx: C, f: closure[Env](&_: T, &_: C) -> Ret) -> Option[Ret] { ... }

Calls f on element i where it lives, with a context cx lent beside it: update, with the linear values f works on, which it cannot capture. Bundle several into one struct.

method sort_unstable_bysource

forall Env where Copy[Env].
fn sort_unstable_by(&self, 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 destroy_withsource

fn destroy_with(self, f: fn(T) -> ()) -> () { ... }

Frees the vector, handing each element to f first.

method sort_unstablesource

fn sort_unstable(&self) { ... }

Sorts the elements in ascending Ord order. Not stable; any T.

method sortsource

fn sort(&self) { ... }

Sorts the elements in ascending Ord order, stably.

method getsource

fn get(&self, i: usize) -> Option[T] { ... }

A copy of element i, or None when it is out of range.

method atsource

fn at(&self, 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 firstsource

fn first(&self) -> Option[T] { ... }

A copy of the first element, or None when there is none.

method lastsource

fn last(&self) -> Option[T] { ... }

A copy of the last element, or None when there is none.

method setsource

fn set(&self, i: usize, value: T) { ... }

Puts value at i, dropping the element there; stops the program when i is out of range.

method truncatesource

fn truncate(&self, len: usize) { ... }

Keeps the first len elements, dropping the rest; nothing changes when there are no more than len.

method clearsource

fn clear(&self) { ... }

Drops every element, keeping the room.

method destroysource

fn destroy(self) -> () { ... }

Frees a vector of Copy elements, which need no per-element callback.

method containssource

fn contains(&self, value: T) -> bool { ... }

Whether some element equals value (Eq).

method sort_bysource

forall C, Env where Copy[Env].
fn sort_by(&self, &cx: C, cmp: closure[Env](&_: C, T, T) -> Order) { ... }

Sorts, stably, by cmp, which is lent the context cx for each comparison (Vec!::sort_by).

method itersource

fn iter(self) -> OwnedVecIter![T] { ... }

An iterator over the elements, holding the vector until OwnedVecIter!::finish hands it back.