[−][src]Trait async_peek::AsyncPeekExt
An extension trait which adds utility methods to AsyncPeek
types.
Provided methods
fn peek<'peek>(&'peek mut self, buf: &'peek mut [u8]) -> Peek<'peek, Self>ⓘ where
Self: Unpin,
Self: Unpin,
Tries to read data into buf
without removing it from the queue.
Returns the number of bytes read, or io::Error
if an error is encountered.
Examples
use async_peek::{AsyncPeek, AsyncPeekExt}; use smol::Async; use std::net::{TcpStream, ToSocketAddrs}; let addr = "127.0.0.1:0".to_socket_addrs()?.next().unwrap(); let mut stream = Async::<TcpStream>::connect(addr).await?; let mut buf = [0; 64]; let n = stream.peek(&mut buf).await?; println!("Peeked {} bytes", n);