#async-io #tokio #io #peek #future #async #io-read

peekable

Peekable reader and async reader, which enhance your network programming experience

2 releases

0.2.3 Mar 21, 2024
0.2.2 Mar 21, 2024
0.2.1 Feb 9, 2024
0.2.0 Jan 29, 2024
0.1.0 Jan 24, 2024

#314 in Asynchronous

Download history 8/week @ 2024-01-28 154/week @ 2024-02-04 762/week @ 2024-02-11 358/week @ 2024-02-18 2271/week @ 2024-02-25 1322/week @ 2024-03-03 4/week @ 2024-03-10 950/week @ 2024-03-17 1174/week @ 2024-03-24 426/week @ 2024-03-31 385/week @ 2024-04-07 326/week @ 2024-04-14

2,774 downloads per month
Used in 4 crates (2 directly)

MIT/Apache

97KB
1.5K SLoC

Peekable

Peekable reader and async reader, which enhance your network programming experience.

github LoC Build codecov

docs.rs crates.io crates.io license

English | 简体中文

Installation

  • Std

    [dependencies]
    peekable = "0.2"
    
  • Tokio I/O

    [dependencies]
    peekable = { version = "0.2", features = ["tokio"] }
    
  • Futures I/O

    [dependencies]
    peekable = { version = "0.2", features = ["future"] }
    

Examples

  • Std

    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

    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

    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);
    

License

peekable is under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE, LICENSE-MIT for details.

Copyright (c) 2024 Al Liu.

Dependencies

~0–1.5MB
~26K SLoC