Crate boxext [−] [src]
This crate provides extra initializer methods for
Box, working around the
current (as of writing) shortcomings from
Since Rust 1.12, constructs such as
Box::new([0; 4096])first create a temporary object on the stack before copying it into the newly allocated space (e.g. issue #50047).
Constructs such as
Box::new(some_function_call())first get the result from the function call on the stack before copying it into the newly allocated space.
Both can be worked around with some contortion but with caveats. This crate provides helpers doing those contortions for you, but can't deal with the caveats. Those caveats are essentially the same as why the unstable placement features were removed in nightly 1.27, namely that there are no guarantees that things will actually happen in place (and they don't in debug builds).
The crates adds the following helper methods to the
new_with, which takes a function or closure returning the object that will be placed in the Box.
std(enabled by default): Uses libstd. Can be disabled to allow use with
no_stdcode, in which case
allocator_apineeds to be enabled.
allocator_api: Add similar helpers to the
Boxtype from the
unstable-rust: Use unstable rust features to more reliably use
callocand co. for
try_new_zeroedmethods that don't panic on OOM. Requires either the
Extensions to the
Trait indicating whether a value full of zeroes is valid.