head-tail-iter 1.1.0

An iterator that repeatedly splits head & tail
Documentation
  • Coverage
  • 100%
    6 out of 6 items documented4 out of 5 items with examples
  • Size
  • Source code size: 21.55 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.73 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • GrigorenkoPV/head-tail-iter
    2 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • GrigorenkoPV

Head-Tail-Iter

An iterator that splits a slice into its head and tail. Then, the tail into its head and tail, and so on.

Iterator's element type is (&'a T, &'a [T]). Iteration continues until there are no elements left. The last yielded value, thus, has the last element of the original slice as its head, and an empty slice as its tail.

Examples

use std::fmt::Write;
use head_tail_iter::HeadTailIterator;

let mut s = String::new();
for x in [0, 1, 2, 3].head_tail_pairs() {
    writeln!(&mut s, "{:?}", x);
}
assert_eq!(s, "\
(0, [1, 2, 3])
(1, [2, 3])
(2, [3])
(3, [])
");
use head_tail_iter::HeadTailIterator;

for (head, tail) in vec![3, 2, 1, 0].head_tail_pairs() {
    assert_eq!(*head, tail.len());
}