Struct async_compat::Compat[][src]

pub struct Compat<T> { /* fields omitted */ }

Compatibility adapter for futures and I/O types.

Implementations

impl<T> Compat<T>[src]

pub fn new(t: T) -> Compat<T>

Notable traits for Compat<T>

impl<T: Future> Future for Compat<T> type Output = T::Output;
[src]

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(())
}))

pub fn get_ref(&self) -> &T[src]

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(())
}))

pub fn get_mut(&mut self) -> &mut T[src]

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(())
}))

pub fn into_inner(self) -> T[src]

Unwraps the compatibility adapter.

Examples

use async_compat::Compat;

let stdout = Compat::new(tokio::io::stdout());
let original = stdout.into_inner();

Trait Implementations

impl<T: AsyncBufRead> AsyncBufRead for Compat<T>[src]

impl<T: AsyncBufRead> AsyncBufRead for Compat<T>[src]

impl<T: AsyncRead> AsyncRead for Compat<T>[src]

impl<T: AsyncRead> AsyncRead for Compat<T>[src]

impl<T: AsyncSeek> AsyncSeek for Compat<T>[src]

impl<T: AsyncSeek> AsyncSeek for Compat<T>[src]

impl<T: AsyncWrite> AsyncWrite for Compat<T>[src]

impl<T: AsyncWrite> AsyncWrite for Compat<T>[src]

impl<T: Future> Future for Compat<T>[src]

type Output = T::Output

The type of value produced on completion.

impl<'__pin, T> Unpin for Compat<T> where
    __Origin<'__pin, T>: Unpin
[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<R> AsyncBufReadExt for R where
    R: AsyncBufRead + ?Sized
[src]

impl<R> AsyncReadExt for R where
    R: AsyncRead + ?Sized
[src]

impl<S> AsyncSeekExt for S where
    S: AsyncSeek + ?Sized
[src]

impl<W> AsyncWriteExt for W where
    W: AsyncWrite + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> CompatExt for T[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<F> IntoFuture for F where
    F: Future
[src]

type Output = <F as Future>::Output

🔬 This is a nightly-only experimental API. (into_future)

The output that the future will produce on completion.

type Future = F

🔬 This is a nightly-only experimental API. (into_future)

Which kind of future are we turning this into?

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<F, T, E> TryFuture for F where
    F: Future<Output = Result<T, E>> + ?Sized
[src]

type Ok = T

The type of successful values yielded by this future

type Error = E

The type of failures yielded by this future

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.