-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
io: Add
AsyncWriteExt::flush
(#1376)
* io: Add `AsyncWriteExt::flush` * fmt * fix clippy
- Loading branch information
1 parent
144d980
commit 6b20272
Showing
4 changed files
with
55 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use std::future::Future; | ||
use std::io; | ||
use std::pin::Pin; | ||
use std::task::{Context, Poll}; | ||
|
||
use tokio_io::AsyncWrite; | ||
|
||
/// A future used to fully flush an I/O object. | ||
/// | ||
/// Created by the [`AsyncWriteExt::flush`] function. | ||
/// | ||
/// [`flush`]: fn.flush.html | ||
#[derive(Debug)] | ||
pub struct Flush<'a, A: ?Sized> { | ||
a: &'a mut A, | ||
} | ||
|
||
/// Creates a future which will entirely flush an I/O object. | ||
pub(super) fn flush<A>(a: &mut A) -> Flush<'_, A> | ||
where | ||
A: AsyncWrite + Unpin + ?Sized, | ||
{ | ||
Flush { a } | ||
} | ||
|
||
impl<'a, A> Unpin for Flush<'a, A> where A: Unpin + ?Sized {} | ||
|
||
impl<A> Future for Flush<'_, A> | ||
where | ||
A: AsyncWrite + Unpin + ?Sized, | ||
{ | ||
type Output = io::Result<()>; | ||
|
||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||
let me = &mut *self; | ||
Pin::new(&mut *me.a).poll_flush(cx) | ||
} | ||
} |
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