Struct async_compat::Compat
source · [−]pub struct Compat<T> { /* private fields */ }
Expand description
Compatibility adapter for futures and I/O types.
Implementations
sourceimpl<T> Compat<T>
impl<T> Compat<T>
sourcepub fn new(t: T) -> Compat<T>ⓘNotable traits for Compat<T>impl<T: Future> Future for Compat<T> type Output = T::Output;
pub fn new(t: T) -> Compat<T>ⓘNotable traits for Compat<T>impl<T: Future> Future for Compat<T> type Output = T::Output;
Applies the compatibility adapter to a future or an I/O type.
Examples
Apply it to a future:
use async_compat::Compat;
use std::time::Duration;
futures::executor::block_on(Compat::new(async {
// We can use tokio's timers because we're inside tokio context.
tokio::time::sleep(Duration::from_secs(1)).await;
}));
Apply it to an I/O type:
use async_compat::{Compat, CompatExt};
use futures::prelude::*;
futures::executor::block_on(Compat::new(async {
// The `write_all` method comes from `futures::io::AsyncWriteExt`.
Compat::new(tokio::io::stdout()).write_all(b"hello\n").await?;
Ok(())
}))
sourcepub fn get_ref(&self) -> &T
pub fn get_ref(&self) -> &T
Gets a shared reference to the inner value.
Examples
use async_compat::Compat;
use tokio::net::UdpSocket;
futures::executor::block_on(Compat::new(async {
let socket = Compat::new(UdpSocket::bind("127.0.0.1:0").await?);
let addr = socket.get_ref().local_addr()?;
Ok(())
}))
sourcepub fn get_mut(&mut self) -> &mut T
pub fn get_mut(&mut self) -> &mut T
Gets a mutable reference to the inner value.
Examples
use async_compat::Compat;
use tokio::net::TcpListener;
futures::executor::block_on(Compat::new(async {
let mut listener = Compat::new(TcpListener::bind("127.0.0.1:0").await?);
let (stream, addr) = listener.get_mut().accept().await?;
let stream = Compat::new(stream);
Ok(())
}))
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Unwraps the compatibility adapter.
Examples
use async_compat::Compat;
let stdout = Compat::new(tokio::io::stdout());
let original = stdout.into_inner();
Trait Implementations
sourceimpl<T: AsyncBufRead> AsyncBufRead for Compat<T>
impl<T: AsyncBufRead> AsyncBufRead for Compat<T>
sourceimpl<T: AsyncBufRead> AsyncBufRead for Compat<T>
impl<T: AsyncBufRead> AsyncBufRead for Compat<T>
sourceimpl<T: AsyncRead> AsyncRead for Compat<T>
impl<T: AsyncRead> AsyncRead for Compat<T>
sourceimpl<T: AsyncWrite> AsyncWrite for Compat<T>
impl<T: AsyncWrite> AsyncWrite for Compat<T>
sourcefn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize>>
fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize>>
Attempt to write bytes from buf
into the object. Read more
sourcefn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
Attempt to flush the object, ensuring that any buffered data reach their destination. Read more
sourceimpl<T: AsyncWrite> AsyncWrite for Compat<T>
impl<T: AsyncWrite> AsyncWrite for Compat<T>
sourcefn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize>>
fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize>>
Attempt to write bytes from buf
into the object. Read more
sourcefn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
Attempts to flush the object, ensuring that any buffered data reach their destination. Read more
sourcefn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
Initiates or attempts to shut down this writer, returning success when the I/O connection has completely shut down. Read more
sourcefn poll_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>]
) -> Poll<Result<usize, Error>>
fn poll_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>]
) -> Poll<Result<usize, Error>>
Like poll_write
, except that it writes from a slice of buffers. Read more
sourcefn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
Determines if this writer has an efficient poll_write_vectored
implementation. Read more
impl<'__pin, T> Unpin for Compat<T> where
__Origin<'__pin, T>: Unpin,
Auto Trait Implementations
impl<T> RefUnwindSafe for Compat<T> where
T: RefUnwindSafe,
impl<T> Send for Compat<T> where
T: Send,
impl<T> Sync for Compat<T> where
T: Sync,
impl<T> UnwindSafe for Compat<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> CompatExt for T
impl<T> CompatExt for T
sourceimpl<F> IntoFuture for F where
F: Future,
impl<F> IntoFuture for F where
F: Future,
type Output = <F as Future>::Output
type Output = <F as Future>::Output
into_future
)The output that the future will produce on completion.
type IntoFuture = F
type IntoFuture = F
into_future
)Which kind of future are we turning this into?
sourcefn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
into_future
)Creates a future from a value.