macro_rules! pin {
($($x:ident),* $(,)?) => { ... };
}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,StreamExtfor 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 operationsPins a variable of type T on the stack and rebinds it as Pin<&mut T>.
use futures_lite::{future, pin};
use std::fmt::Debug;
use std::future::Future;
use std::pin::Pin;
use std::time::Instant;
// Inspects each invocation of `Future::poll()`.
async fn inspect<T: Debug>(f: impl Future<Output = T>) -> T {
pin!(f);
future::poll_fn(|cx| dbg!(f.as_mut().poll(cx))).await
}
let f = async { 1 + 2 };
inspect(f).await;