Map Box
Map the value in a Box, re-using the allocation when possible.
For example, this code will not re-allocate.
use Map;
let b = Box new;
let b = b.map_box;
The signature of map
is:
Limitations
If the alignment requirements of the type changes, even if the alignment becomes lower, the Box needs to be reallocated. This is because:
- alloc::dealloc requires the layout to be identical to the layout that the allocation was made with
- alloc::realloc only takes a new size, it cannot change the layout of the allocation downwards