3 unstable releases

0.2.0 Jun 29, 2022
0.1.1 Jun 29, 2022
0.1.0 Jun 29, 2022

#492 in Memory management

49 downloads per month
Used in 2 crates (via doublets)

MIT license

3KB

Leak &mut [T] in favor of NonNull<[T]>

use leak_slice::LeakSliceExt;
use std::mem::forget;

fn main() {
    let slice = &mut [1, 3, 3, 7][..];
    let ptr = slice.leak();

    // forget about the slice
    forget(slice); // optional, but still don't use slice

    // SAFETY: we forgot about the slice
    unsafe {
        assert_eq!(ptr.as_ref(), [1, 3, 3, 7]);
    }
}

No runtime deps