Crates.io | boxify |
lib.rs | boxify |
version | 0.1.0 |
source | src |
created_at | 2024-02-06 00:02:26.835953 |
updated_at | 2024-02-06 00:02:26.835953 |
description | Place your values directly on the heap without creating them on the stack first. |
homepage | |
repository | https://github.com/chipshort/boxify |
max_upload_size | |
id | 1128120 |
size | 11,414 |
This crate provides a macro to initialize your Box<T>
on the heap without having to have it on the stack before.
This allows easily putting big arrays or structs containing them into a Box
without overflowing the stack:
// this would overflow the stack:
// let e = Box::new(Example {
// huge_array: [42; 1024 * 1024 * 1024],
// });
// this does not:
let e = boxify::boxify!(Example {
huge_array: [42; 1024 * 1024 * 1024],
});
Currently, this supports tuples, arrays and structs, even deeply nested ones. Take a look at the examples
folder to
see what's possible.
All other types are constructed on the stack and put into the box later.
Test { ..test }
is not allowed and causes a compiler error.
This is because the macro needs to know all of the struct fields to fill them.