Peekable

Peekable reader and async reader, which enhance your network programming experience. [github][Github-url] LoC [Build][CI-url] [codecov][codecov-url] [docs.rs][doc-url] [crates.io][crates-url] [crates.io][crates-url] license English | [简体中文][zh-cn-url]
## Installation - **Std** ```toml [dependencies] peekable = "0.2" ``` - **Tokio I/O** ```toml [dependencies] peekable = { version = "0.2", features = ["tokio"] } ``` - **Futures I/O** ```toml [dependencies] peekable = { version = "0.2", features = ["future"] } ``` ## Examples - **Std** ```rust use std::{net::TcpStream, io::Read}; use peekable::Peekable; let conn = TcpStream::connect("127.0.0.1:8080").unwrap(); let mut peekable = Peekable::from(conn); let mut peeked = [0; 16]; peekable.peek_exact(&mut peeked).unwrap(); let mut readed = [0; 16]; peekable.read_exact(&mut readed).unwrap(); assert_eq!(peeked, readed); ``` - **Tokio I/O** ```rust use tokio::{net::TcpStream, io::AsyncReadExt}; use peekable::tokio::AsyncPeekable; let conn = TcpStream::connect("127.0.0.1:8080").await.unwrap(); let mut peekable = AsyncPeekable::from(conn); let mut peeked = [0; 16]; peekable.peek_exact(&mut peeked).await.unwrap(); let mut readed = [0; 16]; peekable.read_exact(&mut readed).await.unwrap(); assert_eq!(peeked, readed); ``` - **Futures I/O** ```rust use async_std::net::TcpStream; use futures::AsyncReadExt; use peekable::future::AsyncPeekable; let conn = TcpStream::connect("127.0.0.1:8080").await.unwrap(); let mut peekable = AsyncPeekable::from(conn); let mut peeked = [0; 16]; peekable.peek_exact(&mut peeked).await.unwrap(); let mut readed = [0; 16]; peekable.read_exact(&mut readed).await.unwrap(); assert_eq!(peeked, readed); ``` ## TODO - [ ] Make peek buffer generic over `const N: usize` - [ ] Add fill peek buffer API #### License `peekable` is under the terms of both the MIT license and the Apache License (Version 2.0). See [LICENSE-APACHE](LICENSE-APACHE), [LICENSE-MIT](LICENSE-MIT) for details. Copyright (c) 2024 Al Liu. [Github-url]: https://github.com/al8n/peekable/ [CI-url]: https://github.com/al8n/peekable/actions/workflows/ci.yml [doc-url]: https://docs.rs/peekable [crates-url]: https://crates.io/crates/peekable [codecov-url]: https://app.codecov.io/gh/al8n/peekable/ [zh-cn-url]: https://github.com/al8n/peekable/tree/main/README-zh_CN.md