Count
Consumes a structural cursor and counts items through its first exhaustion.
Module std.iteration
import std.iteration;Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.
Count
pub fn Count<I>(mut Cursor: I) -> usize where I: IteratorConsumes a structural cursor and counts items through its first exhaustion.
Performs one Next call per item and one final exhaustion test. It allocates nothing and destroys discarded owning items normally; reference items remain nonretaining aliases. No numeric element type or external associated-type projection is required. A nonterminating source produces a nonterminating count; usize overflow uses Sn's checked arithmetic trap. Source callbacks may have their documented costs and side effects. Traversal is synchronous. I: Any structurally satisfied Iterator cursor. Cursor: Traversal state; move a non-Copy input to transfer its ownership. Return: Number of yielded items, after releasing the consumed cursor state. Warning: Does not retain backing storage or provide concurrent access protection.
Example
module example.count_iterator;
from std.iteration import Count, Take, Skip;
fn Main() -> i32 {
let Range = 0_i32..10_i32;
var Tail = Skip<i32>(Range.CreateIterator(), 3);
var Prefix = Take<i32>(move(Tail), 4);
if Count(move(Prefix)) != 4 { return 1; }
if Count((0_i32..0_i32).CreateIterator()) != 0 { return 2; }
return 0;
}