# `boxpin`
`boxpin` is a tiny Rust crate that exposes `Box::pin(...)` as a readable suffix:
```rust
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:
```rust
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
```rust
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:
```bash
cargo test
cargo bench
```