pub struct Compat<T> { /* private fields */ }
Expand description

Compatibility adapter for futures and I/O types.

Implementations

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

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

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

Unwraps the compatibility adapter.

Examples
use async_compat::Compat;

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

Trait Implementations

Attempt to return the contents of the internal buffer, filling it with more data from the inner reader if it is empty. Read more

Tells this buffer that amt bytes have been consumed from the buffer, so they should no longer be returned in calls to poll_read. Read more

Attempts to return the contents of the internal buffer, filling it with more data from the inner reader if it is empty. Read more

Tells this buffer that amt bytes have been consumed from the buffer, so they should no longer be returned in calls to poll_read. Read more

Attempt to read from the AsyncRead into buf. Read more

Attempt to read from the AsyncRead into bufs using vectored IO operations. Read more

Attempts to read from the AsyncRead into buf. Read more

Attempt to seek to an offset, in bytes, in a stream. Read more

Attempts to seek to an offset, in bytes, in a stream. Read more

Waits for a seek operation to complete. Read more

Attempt to write bytes from buf into the object. Read more

Attempt to flush the object, ensuring that any buffered data reach their destination. Read more

Attempt to close the object. Read more

Attempt to write bytes from bufs into the object using vectored IO operations. Read more

Attempt to write bytes from buf into the object. Read more

Attempts to flush the object, ensuring that any buffered data reach their destination. Read more

Initiates or attempts to shut down this writer, returning success when the I/O connection has completely shut down. Read more

Like poll_write, except that it writes from a slice of buffers. Read more

Determines if this writer has an efficient poll_write_vectored implementation. Read more

The type of value produced on completion.

Attempt to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Applies the Compat adapter by value. Read more

Applies the Compat adapter by shared reference. Read more

Applies the Compat adapter by mutable reference. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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

The output that the future will produce on completion.

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

Which kind of future are we turning this into?

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

Creates a future from a value.

The type returned in the event of a conversion error.

Performs the conversion.

The type of successful values yielded by this future

The type of failures yielded by this future

Poll this TryFuture as if it were a Future. Read more

The type returned in the event of a conversion error.

Performs the conversion.