Module std::slice
Views of T slots: a Slice<T> is len slots of storage lent by its owner (Buf::slice,
Buf::slice_mut), always behind & or &mut. The forms s[i], &mut s[i], s[i] = x,
&s[lo..hi] and for x in s call these: the plain ones require the index fact, the
_checked ones raise Panic instead.
Source: std/slice.weir; committed interface: std/slice.iface. Index
- fn
get: A copy of sloti;imust be belows.len(R-EntryFactotherwise). Whats[i]calls when the fact is known. - fn
get_checked: A copy of sloti, or apanic(with Panic) wheniis out of bounds. - fn
get_ref: A shared reference to sloti, borrowings[i];imust be belows.len. - fn
get_ref_checked: A shared reference to sloti, or apanicwheniis out of bounds. - fn
get_mut: A mutable reference to sloti(what&mut s[i]ands[i] = xuse);imust be belows.len. - fn
get_mut_checked: A mutable reference to sloti, or apanicwheniis out of bounds. - fn
replace_at: Writesxinto slotiand returns the old value, so it works for non-copyT;imust be belows.len. - fn
replace_at_checked:replace_at, or apanicwheniis out of bounds. ItsPanicclause isterminal(it does not resume), sincexwould otherwise be lost. - fn
range: The subviews[lo..hi], no copy; requireslo <= hiandhi <= s.len. - fn
range_checked: The subviews[lo..hi], or apanicwhenlo > hiorhi > s.len. - fn
range_mut: The mutable subviews[lo..hi]; requireslo <= hiandhi <= s.len. - fn
range_mut_checked: The mutable subviews[lo..hi], or apanicwhen the range is out of bounds. - fn
copy_within: Copies the elementslo..hito the slots fromdst(the ranges may overlap), like Rust'scopy_within; panics when either range is not inside the view. There is no proved form. - fn
iter: An iterator over copies of the slice's elements, first to last. It borrows the slice while it lives. - struct
SliceIter: The iteratoriterreturns: copies of a slice's elements, borrowing the slice.
fn get
pub fn get<T: copy, r>(s: &Slice<T> in r, i: usize) -> T requires i < s.len
A copy of slot i; i must be below s.len (R-EntryFact otherwise). What s[i] calls
when the fact is known.
Committed interface (std/slice.iface): the signature alone.
fn get_checked
pub fn get_checked<T: copy, r>(s: &Slice<T> in r, i: usize) -> T with Panic {panic: raise}
A copy of slot i, or a panic (with Panic) when i is out of bounds.
Committed interface (std/slice.iface):
bound Panic: Panic any
aborts: Panic.panic
scheduling point: Panic not quiet
fn get_ref
pub fn get_ref<T, r>(s: &Slice<T> in r, i: usize) -> &{s[i]} T requires i < s.len
A shared reference to slot i, borrowing s[i]; i must be below s.len.
Committed interface (std/slice.iface): the signature alone.
fn get_ref_checked
pub fn get_ref_checked<T, r>(s: &Slice<T> in r, i: usize) -> &{s[i]} T with Panic {panic: raise}
A shared reference to slot i, or a panic when i is out of bounds.
Committed interface (std/slice.iface):
bound Panic: Panic any
aborts: Panic.panic
scheduling point: Panic not quiet
fn get_mut
pub fn get_mut<T, r>(s: &mut Slice<T> in r, i: usize) -> &{s[i]} mut T requires i < s.len
A mutable reference to slot i (what &mut s[i] and s[i] = x use); i must be below
s.len.
Committed interface (std/slice.iface): the signature alone.
fn get_mut_checked
pub fn get_mut_checked<T, r>(s: &mut Slice<T> in r, i: usize) -> &{s[i]} mut T with
Panic {panic: raise},
A mutable reference to slot i, or a panic when i is out of bounds.
Committed interface (std/slice.iface):
bound Panic: Panic any
aborts: Panic.panic
scheduling point: Panic not quiet
fn replace_at
pub fn replace_at<T, r>(s: &mut Slice<T> in r, i: usize, x: T) -> T requires i < s.len
Writes x into slot i and returns the old value, so it works for non-copy T; i
must be below s.len.
Committed interface (std/slice.iface):
stores T in regions r
fn replace_at_checked
pub fn replace_at_checked<T, r>(s: &mut Slice<T> in r, i: usize, x: T) -> T with
Panic {panic: terminal},
replace_at, or a panic when i is out of bounds. Its Panic clause is terminal
(it does not resume), since x would otherwise be lost.
Committed interface (std/slice.iface):
bound Panic: Panic { panic: terminal } any
scheduling point: Panic not quiet
stores T in regions r
fn range
pub fn range<T, r>(
s: &Slice<T> in r,
lo: usize,
hi: usize,
) -> &{s[lo..hi]} Slice<T> in r requires lo <= hi, hi <= s.len
The subview s[lo..hi], no copy; requires lo <= hi and hi <= s.len.
Committed interface (std/slice.iface): the signature alone.
fn range_checked
pub fn range_checked<T, r>(
s: &Slice<T> in r,
lo: usize,
hi: usize,
) -> &{s[lo..hi]} Slice<T> in r with Panic {panic: raise}
The subview s[lo..hi], or a panic when lo > hi or hi > s.len.
Committed interface (std/slice.iface):
bound Panic: Panic any
aborts: Panic.panic
scheduling point: Panic not quiet
fn range_mut
pub fn range_mut<T, r>(
s: &mut Slice<T> in r,
lo: usize,
hi: usize,
) -> &{s[lo..hi]} mut Slice<T> in r requires lo <= hi, hi <= s.len
The mutable subview s[lo..hi]; requires lo <= hi and hi <= s.len.
Committed interface (std/slice.iface): the signature alone.
fn range_mut_checked
pub fn range_mut_checked<T, r>(
s: &mut Slice<T> in r,
lo: usize,
hi: usize,
) -> &{s[lo..hi]} mut Slice<T> in r with Panic {panic: raise}
The mutable subview s[lo..hi], or a panic when the range is out of bounds.
Committed interface (std/slice.iface):
bound Panic: Panic any
aborts: Panic.panic
scheduling point: Panic not quiet
fn copy_within
pub fn copy_within<T: copy, r>(s: &mut Slice<T> in r, lo: usize, hi: usize, dst: usize) with
Panic {panic: raise},
Copies the elements lo..hi to the slots from dst (the ranges may overlap), like Rust's
copy_within; panics when either range is not inside the view. There is no proved form.
Committed interface (std/slice.iface):
bound Panic: Panic any
aborts: Panic.panic
scheduling point: Panic not quiet
stores T in regions r
fn iter
pub fn iter<T: copy>(s: &Slice<T>) -> SliceIter<T>
An iterator over copies of the slice's elements, first to last. It borrows the slice while it lives.
Committed interface (std/slice.iface): the signature alone.
struct SliceIter
pub struct SliceIter<T>: forget {
/* private fields */
}
The iterator iter returns: copies of a slice's elements, borrowing the slice.
Implementations:
impl<T: copy> Iterator for SliceIter<T>