[][src]Trait async_peek::AsyncPeekExt

pub trait AsyncPeekExt: AsyncPeek {
    fn peek<'peek>(&'peek mut self, buf: &'peek mut [u8]) -> Peek<'peek, Self>

Notable traits for Peek<'_, P>

impl<P: AsyncPeek + Unpin, '_> Future for Peek<'_, P> type Output = Result<usize, Error>;

    where
        Self: Unpin
, { ... } }

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>

Notable traits for Peek<'_, P>

impl<P: AsyncPeek + Unpin, '_> Future for Peek<'_, P> type Output = Result<usize, Error>;
where
    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);
Loading content...

Implementors

impl<P: AsyncPeek + ?Sized> AsyncPeekExt for P[src]

Loading content...