take_while_with_failure 0.1.0

Adds a `take_while_with_failure` iterator that behaves identically to `take_while`, but also includes the first element that fails.
Documentation
  • Coverage
  • 25%
    1 out of 4 items documented0 out of 3 items with examples
  • Size
  • Source code size: 15.84 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.16 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Homepage
  • euank/take_while_with_failure.rs
    3 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • euank

Take While with Failure

This library implements an additional iterator for rust.

Creates an iterator that yields elements as long as the predicate returns true. Additionally, it includes the first element that returns false, after which no further elements will be yielded.

This can be useful if, for example, you would like to read a stream until the first error and then stop processing immediately without losing the error.

Example

let a = [1, 2, 3, 4, 5];
let mut it = a.iter().take_while_with_failure(|&a| *a < 2);
assert_eq!(it.next(), Some(&1));
assert_eq!(it.next(), Some(&2));
assert!(it.next().is_none());