empty-box

Crates.ioempty-box
lib.rsempty-box
version0.1.1
sourcesrc
created_at2017-06-01 19:40:12.652752
updated_at2017-06-01 19:42:01.76112
descriptionAllows for `Box`s to have their values moved out and replaced with new values, while reusing the same allocation.
homepagehttps://github.com/sdleffler/empty-box-rs
repositoryhttps://github.com/sdleffler/empty-box-rs
max_upload_size
id17230
size17,248
Shea Leffler (sdleffler)

documentation

https://docs.rs/empty-box

README

Build Status Docs Status On crates.io

EmptyBox, a way to safely move values in and out of Boxs without

reallocations

EmptyBox is similar to a statically checked Box<Option<T>>:

use empty_box::EmptyBox;

// A box with a string!
let boxed = Box::new("Hello!".to_string());

// Oh no, we don't like that string.
let (string, empty) = EmptyBox::take(boxed);

// Let's make an objectively superior string, and put it into the original
// box.
let superior = "Objectively superior string!".to_string();

// Now we have our superior string in the box!
let boxed = empty.put(superior); 

assert_eq!("Hello!", string);
assert_eq!("Objectively superior string!", &*boxed);

Creating an EmptyBox from a Box and then putting a T back into the EmptyBox will avoid allocating a new Box, instead reusing whatever old Box the T was EmptyBox::taken from.

License

Licensed under either of

at your option.

Contribution

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.

Commit count: 7

cargo fmt