Flat drop
In this crate, we define the FlatDrop type.
FlatDrop<K> behaves just like a K, but with a custom Drop implementation
that avoids blowing up the stack when dropping large objects.
Instead of recursively dropping subobjects, we perform a depth-first search
and iteratively drop subobjects.
To use this crate, you can replace recursive Boxes and Arcs in your types
with FlatDrop<Box<T>> or FlatDrop<Arc<T>>. You'll need to implement the
Recursive trait for your type, which performs one step of the iterative
dropping procedure.
This crate uses unsafe internally, but the external API is safe.
Example
use ;
/// Peano natural numbers.
// Create a new thread with a 4kb stack and allocate a number far bigger than 4 * 1024.
const STACK_SIZE: usize = 4 * 1024;
new
.stack_size
.spawn
.unwrap
.join
.unwrap;