#iterator #take #until

take-until

A take until extension for iterators

1 unstable release

0.1.0 Sep 10, 2019

#890 in Rust patterns

Download history 6919/week @ 2022-08-17 7499/week @ 2022-08-24 7309/week @ 2022-08-31 6825/week @ 2022-09-07 6698/week @ 2022-09-14 7174/week @ 2022-09-21 6530/week @ 2022-09-28 6486/week @ 2022-10-05 7308/week @ 2022-10-12 6512/week @ 2022-10-19 6477/week @ 2022-10-26 6550/week @ 2022-11-02 6542/week @ 2022-11-09 6539/week @ 2022-11-16 6861/week @ 2022-11-23 6044/week @ 2022-11-30

26,913 downloads per month
Used in 6 crates (3 directly)

MIT license

5KB
81 lines

Take Until

Actions Status

This crate adds the take_until method as an extension for iterators.

Example

Parsing the next base 128 varint from a byte slice.

use take_until::TakeUntilExt;

let varint = &[0b1010_1100u8, 0b0000_0010, 0b1000_0001];
let int: u32 = varint
    .iter()
    .take_until(|b| (**b & 0b1000_0000) == 0)
    .enumerate()
    .fold(0, |acc, (i, b)| {
        acc | ((*b & 0b0111_1111) as u32) << (i * 7)
     });
assert_eq!(300, int);

lib.rs:

This crate adds the take_until method as an extension for iterators.

Example

Parsing the next base 128 varint from a byte slice.

use take_until::TakeUntilExt;

let varint = &[0b1010_1100u8, 0b0000_0010, 0b1000_0001];
let int: u32 = varint
    .iter()
    .take_until(|b| (**b & 0b1000_0000) == 0)
    .enumerate()
    .fold(0, |acc, (i, b)| {
        acc | ((*b & 0b0111_1111) as u32) << (i * 7)
     });
assert_eq!(300, int);

No runtime deps