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

peekable

Peekable读取器和异步读取器,可提升您的网络编程体验

2个版本

0.2.3 2024年3月21日
0.2.2 2024年3月21日
0.2.1 2024年2月9日
0.2.0 2024年1月29日
0.1.0 2024年1月24日

#493 in 异步

Download history 72/week @ 2024-04-22 26/week @ 2024-05-20 23/week @ 2024-05-27 13/week @ 2024-06-03 16/week @ 2024-06-10 9/week @ 2024-06-17 23/week @ 2024-06-24 19/week @ 2024-07-01 3/week @ 2024-07-08 16/week @ 2024-07-15 4/week @ 2024-07-22 32/week @ 2024-07-29 10/week @ 2024-08-05

每月 62 次下载
4 Crate中使用(直接使用2个)

MIT/Apache

97KB
1.5K SLoC

Peekable

Peekable读取器和异步读取器,可提升您的网络编程体验。

github LoC Build codecov

docs.rs crates.io crates.io license

英语 | 简体中文

安装

  • 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"] }
    

示例

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

许可证

peekable 在MIT许可证和Apache许可证(版本2.0)下。

请参阅 LICENSE-APACHELICENSE-MIT 以获取详细信息。

版权所有 (c) 2024 Al Liu。

依赖项

~0–1.5MB
~26K SLoC