Skip to content

ae2rs/boxpin

Repository files navigation

boxpin

CI Crates.io Docs.rs License

boxpin is a tiny Rust crate that exposes Box::pin(...) as a readable suffix:

use boxpin::BoxPinExt;

let future = async { 42 }.pinned();
let value = futures::executor::block_on(future);

assert_eq!(value, 42);

It does not perform type erasure and it does not return BoxFuture. It is exactly equivalent to:

let future = Box::pin(async { 42 });

Why

This repo started as a benchmark project comparing .boxed() and Box::pin(). .boxed() is often nicer to read in suffix-heavy async code, but it also adds type erasure and dynamic dispatch. boxpin keeps the suffix ergonomics while preserving the concrete type inside Pin<Box<T>>.

Crate API

pub trait BoxPinExt: Sized {
    fn pinned(self) -> Pin<Box<Self>>;
}

The trait is implemented for every Sized type, so .pinned() also works for plain values, not just futures.

Local Benchmarks

This repository still contains the local Criterion benchmark harness used to compare:

  • no boxing
  • Box::pin(...)
  • .boxed()

Run it with:

cargo test
cargo bench

License

Licensed under either of:

About

No description, website, or topics provided.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors