michaellass/aligned_box

Resizeable call for array's

Closed this issue · 2 comments

When the type is a [T] it would be useful if there were a way to reallocate it (using alloc::realloc internally) to a different size while preserving the matching prior existing contents for whatever would fit in the new size (meaning any excess would need to be dropped).

Also, as an aside, why container: std::option::Option<std::boxed::Box<T>>, instead of using ManuallyDrop instead? I'm not sure it should matter but it seems more correct overall...

When the type is a [T] it would be useful if there were a way to reallocate it (using alloc::realloc internally) to a different size while preserving the matching prior existing contents for whatever would fit in the new size (meaning any excess would need to be dropped).

I think that would indeed be a nice addition. I will look at this on next occasion. Pull requests are of course also welcome, if you'd like to add this yourself.

Also, as an aside, why container: std::option::Option<std::boxed::Box<T>>, instead of using ManuallyDrop instead? I'm not sure it should matter but it seems more correct overall...

An honest answer is probably that I did not know about ManuallyDrop when writing this crate. Looks like it should also work as it provides a take method that takes a &mut. Also something I will look into closer on next occasion.

Oops, looks like I spammed this bug report by regularly rebasing commits. Anyway, both suggestions are now implemented in master and I will push a new release to crates.io soon.