SliceIterator
Traverses a borrowed contiguous sequence as read-only element references.
Module std.iteration
import std.iteration;Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.
SliceIterator
pub final class SliceIterator<T>Traverses a borrowed contiguous sequence as read-only element references.
The cursor allocates nothing and does not own or retain its slice storage. Moving or destroying the owner, or a documented structural mutation, may invalidate the cursor and all yielded references.
T: Element type of the borrowed contiguous sequence, yielded through read-only references.
Example
module example.slice_iterator;
fn Main() -> i32 {
let Values: i32[3] = [1, 2, 3];
var Cursor = Values.CreateIterator();
var Sum = 0;
while Cursor.Next() is .Some { Value = Item } {
Sum += Item;
}
return Sum - 6;
}SliceIterator.Next
pub fn Next() -> T&?Advances once and borrows the next element. Return: The next read-only reference or none after exhaustion. Warning: The returned reference never outlives the backing storage and is invalidated by its owner's documented mutation rules.
WritableSliceIterator
pub final class WritableSliceIterator<T>Traverses a borrowed contiguous sequence as writable references.
The cursor carries no uniqueness proof and allocates nothing. Its creator must have writable source access; callers remain responsible for ordinary alias and invalidation rules. T: Element type of the borrowed writable sequence, yielded through writable references.
WritableSliceIterator.Next
pub fn Next() -> mut T&?Advances once and borrows the next element with writable access. Return: The next writable reference or none after exhaustion. Warning: The reference and cursor obey the backing owner's exact structural-mutation invalidation boundary.