| Crates.io | map_box |
| lib.rs | map_box |
| version | 0.2.2 |
| created_at | 2024-02-02 12:34:56.001296+00 |
| updated_at | 2024-02-02 13:27:34.191391+00 |
| description | Map the value in a Box, re-using the allocation when possible. |
| homepage | |
| repository | https://github.com/JonathanBrouwer/map_box |
| max_upload_size | |
| id | 1124300 |
| size | 8,457 |
Map the value in a Box, re-using the allocation when possible.
For example, this code will not re-allocate.
use map_box::Map;
let b = Box::new(42u64);
let b = b.map_box(|v| v as i64);
The signature of map is:
impl<T1> Box<T1> {
fn map_box<T2>(self, f: impl FnMut(T1) -> T2) -> Box<T2>;
}
If the alignment requirements of the type changes, even if the alignment becomes lower, the Box needs to be reallocated. This is because: