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