boxpin 0.1.0

A tiny extension trait that exposes Box::pin as a .pinned() suffix.
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented1 out of 3 items with examples
  • Size
  • Source code size: 32.16 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 246.28 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 3s Average build duration of successful builds.
  • all releases: 3s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • ae2rs/boxpin
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ae2rs

boxpin

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