Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AsyncRead::poll_read_buf and AsyncWrite::poll_write_buf
- Loading branch information
Showing
11 changed files
with
299 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use futures_core::future::Future; | ||
use futures_core::task::{Context, Poll}; | ||
use futures_io::{AsyncRead, BufMut}; | ||
use std::io; | ||
use std::pin::Pin; | ||
|
||
/// Future for the [`read_buf`](super::AsyncReadExt::read_buf) method. | ||
#[derive(Debug)] | ||
#[must_use = "futures do nothing unless you `.await` or poll them"] | ||
pub struct ReadBuf<'a, R: ?Sized + Unpin, B> { | ||
reader: &'a mut R, | ||
buf: &'a mut B, | ||
} | ||
|
||
impl<R: ?Sized + Unpin, B> Unpin for ReadBuf<'_, R, B> {} | ||
|
||
impl<'a, R: AsyncRead + ?Sized + Unpin, B: BufMut> ReadBuf<'a, R, B> { | ||
pub(super) fn new(reader: &'a mut R, buf: &'a mut B) -> Self { | ||
Self { reader, buf } | ||
} | ||
} | ||
|
||
impl<R: AsyncRead + ?Sized + Unpin, B: BufMut> Future for ReadBuf<'_, R, B> { | ||
type Output = io::Result<usize>; | ||
|
||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||
let this = &mut *self; | ||
Pin::new(&mut this.reader).poll_read_buf(cx, this.buf) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use futures_core::future::Future; | ||
use futures_core::task::{Context, Poll}; | ||
use futures_io::{AsyncWrite, Buf}; | ||
use std::io; | ||
use std::pin::Pin; | ||
|
||
/// Future for the [`write_buf`](super::AsyncWriteExt::write_buf) method. | ||
#[derive(Debug)] | ||
#[must_use = "futures do nothing unless you `.await` or poll them"] | ||
pub struct WriteBuf<'a, W: ?Sized + Unpin, B> { | ||
writer: &'a mut W, | ||
buf: &'a mut B, | ||
} | ||
|
||
impl<W: ?Sized + Unpin, B> Unpin for WriteBuf<'_, W, B> {} | ||
|
||
impl<'a, W: AsyncWrite + ?Sized + Unpin, B: Buf> WriteBuf<'a, W, B> { | ||
pub(super) fn new(writer: &'a mut W, buf: &'a mut B) -> Self { | ||
Self { writer, buf } | ||
} | ||
} | ||
|
||
impl<W: AsyncWrite + ?Sized + Unpin, B: Buf> Future for WriteBuf<'_, W, B> { | ||
type Output = io::Result<usize>; | ||
|
||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||
let this = &mut *self; | ||
Pin::new(&mut this.writer).poll_write_buf(cx, this.buf) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.