Struct async_compat::Compat
source · pub struct Compat<T> { /* private fields */ }
Expand description
Compatibility adapter for futures and I/O types.
Implementations§
source§impl<T> Compat<T>
impl<T> Compat<T>
sourcepub fn new(t: T) -> Compat<T> ⓘ
pub fn new(t: T) -> Compat<T> ⓘ
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§
source§impl<T: AsyncBufRead> AsyncBufRead for Compat<T>
impl<T: AsyncBufRead> AsyncBufRead for Compat<T>
source§impl<T: AsyncBufRead> AsyncBufRead for Compat<T>
impl<T: AsyncBufRead> AsyncBufRead for Compat<T>
source§impl<T: AsyncRead> AsyncRead for Compat<T>
impl<T: AsyncRead> AsyncRead for Compat<T>
source§impl<T: AsyncWrite> AsyncWrite for Compat<T>
impl<T: AsyncWrite> AsyncWrite for Compat<T>
source§fn 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 moresource§fn 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
source§impl<T: AsyncWrite> AsyncWrite for Compat<T>
impl<T: AsyncWrite> AsyncWrite for Compat<T>
source§fn 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 moresource§fn 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
source§fn 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
source§fn 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 moresource§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
Determines if this writer has an efficient
poll_write_vectored
implementation. Read moreimpl<'__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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<F> IntoFuture for Fwhere
F: Future,
impl<F> IntoFuture for Fwhere F: Future,
§type IntoFuture = F
type IntoFuture = F
Which kind of future are we turning this into?
source§fn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
Creates a future from a value. Read more