smallbox

Build Status crates.io docs.rs

Small Box optimization: store small item on the stack and fallback to heap for large item.

Documentation

# Usage

First, add the following to your Cargo.toml:

toml [dependencies] smallbox = "0.5"

Next, add this to your crate root:

rust extern crate smallbox;

If you want this crate to work with dynamic-sized type, you can request it via:

toml [dependencies] smallbox = { version = "0.5", features = ["unsize"] }

Currently smallbox by default links to the standard library, but if you would instead like to use this crate in a #![no_std] situation or crate, and want to opt out heap dependency and SmallBox<T> type, you can request this via:

toml [dependencies.smallbox] version = "0.5" features = ["unsize"] default-features = false

Enable heap feature for #![no_std] build to link to alloc crate and bring SmallBox<T> back.

toml [dependencies.smallbox] version = "0.5" features = ["unsize", "heap"] default-features = false

# Feature Flags

This crate has the following cargo feature flags:

Benchmark

The test platform is Windows 10 on Intel E3 v1230 v3.

``` running 6 tests test boxlargeitem ... bench: 102 ns/iter (+/- 15) test boxsmallitem ... bench: 48 ns/iter (+/- 16) test smallboxlargeitemlargespace ... bench: 64 ns/iter (+/- 1) test smallboxlargeitemsmallspace ... bench: 113 ns/iter (+/- 14) test smallboxsmallitemlargespace ... bench: 17 ns/iter (+/- 0) test smallboxsmallitemsmallspace ... bench: 6 ns/iter (+/- 0)

test result: ok. 0 passed; 0 failed; 0 ignored; 6 measured; 0 filtered out ```

Roadmap

Contribution

All kinds of contribution are welcome.

License

Licensed under either of

at your option.