tinybox
TinyBox
is like Box
, but with an optimization that avoids allocations for small data-structures. This works by storing the value-bits inside the box itself, when the data-structure fits inside a pointer. This is especially usefull for dynamically sized types like traits.
Example
This example stores a value inside the TinyBox
without requireing an allocation.
use TinyBox;
let boxed = new;
assert_eq!
This looks not very usefull, because the value can be stored inside a usize
variable without TinyBox
. Here is an more useful example that uses dyn-traits. The tinybox!
macro is used to coerce the value to a dyn-trait in stable-rust.
use ;
use ;
let boxed: = tinybox!;
assert_eq!;
assert_eq!;
no_std
This crate should also work without std
. No additional configuration required.
License
This repository is licensed under either of
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.