#iterator #peek #peekable #iterator-adapter #lookahead #multipeek

无std peekmore

类似于Peekable的迭代器适配器,但可以向前预览多个元素

17个版本 (5个稳定版)

1.3.0 2023年6月5日
1.2.0 2023年3月16日
1.0.0 2020年12月30日
0.5.6 2020年8月27日
0.4.0 2019年9月20日

#28 in 无标准库

Download history 383/week @ 2024-03-13 689/week @ 2024-03-20 571/week @ 2024-03-27 678/week @ 2024-04-03 513/week @ 2024-04-10 508/week @ 2024-04-17 463/week @ 2024-04-24 616/week @ 2024-05-01 366/week @ 2024-05-08 409/week @ 2024-05-15 365/week @ 2024-05-22 413/week @ 2024-05-29 416/week @ 2024-06-05 361/week @ 2024-06-12 428/week @ 2024-06-19 488/week @ 2024-06-26

1,745 每月下载量
用于 28 个crate(15个直接使用)

MIT/Apache

69KB
1K SLoC

peekmore

这个crate引入了一个多预览迭代器。这个迭代器类似于 core::iterator::Peekable。主要区别是Peekable只能让你预览下一个元素,不能更远。这个crate旨在消除这个限制。

文档和更多示例用法可以在 docs.rs/peekmore 找到。

使用示例

use peekmore::PeekMore;

fn main() {
    let range10 = 0..11;
    let mut peekable = range10.peekmore();
    
    // Peek at the first element
    let peek_first = peekable.peek();
    assert_eq!(*peek_first.unwrap(), 0);
    
    let peek_first_redux = peekable.peek_nth(0);
    assert_eq!(*peek_first_redux.unwrap(), 0);
    
    // Peek at the 10th (index) element
    let peek_tenth = peekable.peek_nth(10);
    assert_eq!(*peek_tenth.unwrap(), 10);
    
    // Consume the 10th element
    let tenth = peekable.nth(10);
    assert_eq!(tenth.unwrap(), 10);
    
    // Show that there are no more elements
    assert_eq!(peekable.peek(), None);
    assert_eq!(peekable.next(), None);
}

许可协议

许可协议为

任选其一。

贡献

除非你明确声明,否则任何有意提交以包含在作品中并由你定义的Apache-2.0许可,均将按照上述双重许可,不附加任何额外条款或条件。

依赖