-
-
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.
- Loading branch information
1 parent
878503f
commit 63377e2
Showing
3 changed files
with
47 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use crate::AsyncWrite; | ||
use std::future::Future; | ||
use std::io; | ||
use std::pin::Pin; | ||
use std::task::{Context, Poll}; | ||
|
||
/// A future used to shutdown an I/O object. | ||
/// | ||
/// Created by the [`AsyncWriteExt::shutdown`] function. | ||
/// | ||
/// [`shutdown`]: fn.shutdown.html | ||
#[derive(Debug)] | ||
pub struct Shutdown<'a, A: ?Sized> { | ||
a: &'a mut A, | ||
} | ||
|
||
/// Creates a future which will shutdown an I/O object. | ||
pub(super) fn shutdown<A>(a: &mut A) -> Shutdown<'_, A> | ||
where | ||
A: AsyncWrite + Unpin + ?Sized, | ||
{ | ||
Shutdown { a } | ||
} | ||
|
||
impl<'a, A> Unpin for Shutdown<'a, A> where A: Unpin + ?Sized {} | ||
|
||
impl<A> Future for Shutdown<'_, 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_shutdown(cx) | ||
} | ||
} |