take_until/
lib.rs

1//! This crate adds the [`TakeUntilExt::take_until`] method as an extension for
2//! iterators.
3//!
4//! # MSRV
5//! The MSRV is `1.56.1` stable.
6//!
7//! # Example
8//!
9//! ## Parsing the next base 128 varint from a byte slice.
10//!
11//! ```rust
12//! use take_until::TakeUntilExt;
13//!
14//! let varint = &[0b1010_1100u8, 0b0000_0010, 0b1000_0001];
15//! let int: u32 = varint
16//!     .iter()
17//!     .take_until(|b| (**b & 0b1000_0000) == 0)
18//!     .enumerate()
19//!     .fold(0, |acc, (i, b)| {
20//!         acc | ((*b & 0b0111_1111) as u32) << (i * 7)
21//!      });
22//! assert_eq!(300, int);
23//! ```
24//!
25//! ## Take Until vs Take While (from Standard Library)
26//! ```rust
27//! use take_until::TakeUntilExt;
28//!
29//! let items = [1, 2, 3, 4, -5, -6, -7, -8];
30//! let filtered_take_while = items
31//!     .into_iter()
32//!     .take_while(|x| *x > 0)
33//!     .collect::<Vec<i32>>();
34//! let filtered_take_until = items
35//!     .into_iter()
36//!     .take_until(|x| *x <= 0)
37//!     .collect::<Vec<i32>>();
38//! assert_eq!([1, 2, 3, 4], filtered_take_while.as_slice());
39//! assert_eq!([1, 2, 3, 4, -5], filtered_take_until.as_slice());
40//! ```
41
42#![deny(clippy::all, clippy::cargo, clippy::nursery)]
43#![deny(missing_docs)]
44#![deny(missing_debug_implementations)]
45
46mod take_until;
47
48pub use crate::take_until::TakeUntilExt;