blob: d1c986298c6a0c4eb385d316b6f104f39849e64d [file] [log] [blame]
use crate::io::AsyncRead;
use futures_core::future::Future;
use futures_core::task::{LocalWaker, Poll};
use std::io;
use std::marker::Unpin;
use std::pin::Pin;
/// A future which can be used to easily read available number of bytes to fill
/// a buffer.
pub struct Read<'a, R: ?Sized + 'a> {
reader: &'a mut R,
buf: &'a mut [u8],
// Pinning is never projected to fields
impl<R: ?Sized> Unpin for Read<'_, R> {}
impl<'a, R: AsyncRead + ?Sized> Read<'a, R> {
pub(super) fn new(reader: &'a mut R, buf: &'a mut [u8]) -> Self {
Read { reader, buf }
impl<R: AsyncRead + ?Sized> Future for Read<'_, R> {
type Output = io::Result<usize>;
fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll<Self::Output> {
let this = &mut *self;
this.reader.poll_read(lw, this.buf)