Struct streamcatcher::future::Compat[][src]

pub struct Compat<T> { /* fields omitted */ }
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

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 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

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

Waits for a seek operation to complete. Read more

Attempt to seek to an offset, in bytes, in a stream. 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

Creates a future which will wait for a non-empty buffer to be available from this I/O object or EOF to be reached. Read more

A convenience for calling [AsyncBufRead::consume] on Unpin IO types. Read more

Creates a future which will read all the bytes associated with this I/O object into buf until the delimiter byte or EOF is reached. This method is the async equivalent to BufRead::read_until. Read more

Creates a future which will read all the bytes associated with this I/O object into buf until a newline (the 0xA byte) or EOF is reached, This method is the async equivalent to BufRead::read_line. Read more

Returns a stream over the lines of this reader. This method is the async equivalent to BufRead::lines. Read more

Returns the contents of the internal buffer, filling it with more data if empty. Read more

Consumes amt buffered bytes. Read more

Reads all bytes and appends them into buf until the delimiter byte or EOF is found. Read more

Reads all bytes and appends them into buf until a newline (the 0xA byte) or EOF is found. Read more

Returns a stream over the lines of this byte stream. Read more

Returns a stream over the contents of this reader split on the specified byte. Read more

Creates an adaptor which will chain this stream with another. Read more

Tries to read some bytes directly into the given buf in asynchronous manner, returning a future type. Read more

Creates a future which will read from the AsyncRead into bufs using vectored IO operations. Read more

Creates a future which will read exactly enough bytes to fill buf, returning an error if end of file (EOF) is hit sooner. Read more

Creates a future which will read all the bytes from this AsyncRead. Read more

Creates a future which will read all the bytes from this AsyncRead. Read more

Helper method for splitting this read/write object into two halves. Read more

Creates an AsyncRead adapter which will read at most limit bytes from the underlying reader. Read more

Reads some bytes from the byte stream. Read more

Like [read()][AsyncReadExt::read()], except it reads into a slice of buffers. Read more

Reads the entire contents and appends them to a Vec. Read more

Reads the entire contents and appends them to a String. Read more

Reads the exact number of bytes required to fill buf. Read more

Creates an adapter which will read at most limit bytes from it. Read more

Converts this [AsyncRead] into a [Stream] of bytes. Read more

Creates an adapter which will chain this stream with another. Read more

Boxes the reader and changes its type to dyn AsyncRead + Send + 'a. Read more

Creates a future which will seek an IO object, and then yield the new position in the object and the object itself. Read more

Creates a future which will return the current seek position from the start of the stream. Read more

Seeks to a new position in a byte stream. Read more

Creates a future which will entirely flush this AsyncWrite. Read more

Creates a future which will entirely close this AsyncWrite.

Creates a future which will write bytes from buf into the object. Read more

Creates a future which will write bytes from bufs into the object using vectored IO operations. Read more

Write data into this object. Read more

Allow using an [AsyncWrite] as a Sink<Item: AsRef<[u8]>>. Read more

Writes some bytes into the byte stream. Read more

Like [write()][AsyncWriteExt::write()], except that it writes a slice of buffers. Read more

Writes an entire buffer into the byte stream. Read more

Flushes the stream to ensure that all buffered contents reach their destination. Read more

Closes the writer. Read more

Boxes the writer and changes its type to dyn AsyncWrite + Send + 'a. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Reads all bytes into buf until the delimiter byte or EOF is reached. Read more

Reads all bytes and appends them into buf until a newline (the 0xA byte) is reached. Read more

Returns a stream over the lines of this byte stream. Read more

Returns a stream over the contents of this reader split on the byte byte. 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

Performs the conversion.

Map this future’s output to a different type, returning a new future of the resulting type. Read more

Map this future’s output to a different type, returning a new future of the resulting type. Read more

Chain on a computation for when a future finished, passing the result of the future to the provided closure f. Read more

Wrap this future in an Either future, making it the left-hand variant of that Either. Read more

Wrap this future in an Either future, making it the right-hand variant of that Either. Read more

Convert this future into a single element stream. Read more

Flatten the execution of this future when the output of this future is itself another future. Read more

Flatten the execution of this future when the successful result of this future is a stream. Read more

Fuse a future such that poll will never again be called once it has completed. This method can be used to turn any Future into a FusedFuture. Read more

Do something with the output of a future before passing it on. Read more

Catches unwinding panics while polling the future. Read more

Create a cloneable handle to this future where all handles will resolve to the same result. Read more

Turn this future into a future that yields () on completion and sends its output to another future on a separate task. Read more

Wrap the future in a Box, pinning it. Read more

Wrap the future in a Box, pinning it. Read more

A convenience for calling Future::poll on Unpin future types.

Evaluates and consumes the future, returning the resulting output if the future is ready after the first call to Future::poll. Read more

A convenience for calling Future::poll() on !Unpin types.

Returns the result of self or other future, preferring self if both are ready. Read more

Returns the result of self or other future, with no preference if both are ready. Read more

Catches panics while polling the future. Read more

Boxes the future and changes its type to dyn Future + Send + 'a. Read more

Boxes the future and changes its type to dyn Future + 'a. Read more

Performs the conversion.

🔬 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.

Reads some bytes from the byte stream. Read more

Like read, except that it reads into a slice of buffers. Read more

Reads all bytes from the byte stream. Read more

Reads all bytes from the byte stream and appends them into a string. Read more

Reads the exact number of bytes required to fill buf. Read more

Creates an adaptor which will read at most limit bytes from it. Read more

Creates a “by reference” adaptor for this instance of Read. Read more

Transforms this Read instance to a Stream over its bytes. Read more

Creates an adaptor which will chain this stream with another. Read more

Seeks to a new position in a byte stream. Read more

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

Flattens the execution of this future when the successful result of this future is a [Sink]. Read more

Maps this future’s success value to a different value. Read more

Maps this future’s success value to a different value, and permits for error handling resulting in the same type. Read more

Maps this future’s error value to a different value. Read more

Maps this future’s Error to a new error type using the Into trait. Read more

Maps this future’s Ok to a new type using the Into trait. Read more

Executes another future after this one resolves successfully. The success value is passed to a closure to create this subsequent future. Read more

Executes another future if this one resolves to an error. The error value is passed to a closure to create this subsequent future. Read more

Do something with the success value of a future before passing it on. Read more

Do something with the error value of a future before passing it on. Read more

Flatten the execution of this future when the successful result of this future is another future. Read more

Flatten the execution of this future when the successful result of this future is a stream. Read more

Unwraps this future’s output, producing a future with this future’s Ok type as its Output type. Read more

Wraps a [TryFuture] into a type that implements Future. Read more

A convenience method for calling [TryFuture::try_poll] on Unpin future types. Read more

The type returned in the event of a conversion error.

Performs the conversion.

Writes some bytes into the byte stream. Read more

Flushes the stream to ensure that all buffered contents reach their destination. Read more

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

Writes an entire buffer into the byte stream. Read more

Writes a formatted string into this writer, returning any error encountered. Read more