ready

Macro ready 

Source
macro_rules! ready {
    ($e:expr $(,)?) => { ... };
}
Expand description

Complete async runtime utilities and traits.

This re-exports all items from futures_lite, providing:

  • Async I/O traits: AsyncRead, AsyncWrite, AsyncBufRead, etc.
  • Stream utilities: Stream, StreamExt for async iteration
  • Future utilities: FutureExt, future::ready, future::pending
  • Async combinators: join!, try_join!, select!
  • I/O utilities: Async file operations, networking, etc.

This saves you from having to import futures_lite directly and provides all the async primitives needed for HTTP operations.

§Examples

§Stream Processing

use http_kit::utils::{stream, StreamExt};

let data = vec!["chunk1", "chunk2", "chunk3"];
let mut stream = stream::iter(data);

while let Some(chunk) = stream.next().await {
    println!("Processing: {}", chunk);
}

§Async I/O

use http_kit::utils::{AsyncReadExt, AsyncWriteExt};

// These traits are available for async I/O operations

Unwraps Poll<T> or returns Pending.

§Examples

use futures_lite::{future, prelude::*, ready};
use std::pin::Pin;
use std::task::{Context, Poll};

fn do_poll(cx: &mut Context<'_>) -> Poll<()> {
    let mut fut = future::ready(42);
    let fut = Pin::new(&mut fut);

    let num = ready!(fut.poll(cx));
    // ... use num

    Poll::Ready(())
}

The ready! call expands to:

let num = match fut.poll(cx) {
    Poll::Ready(t) => t,
    Poll::Pending => return Poll::Pending,
};