leak_slice

Crates.ioleak_slice
lib.rsleak_slice
version0.2.0
sourcesrc
created_at2022-06-29 09:24:46.995952
updated_at2022-06-29 20:00:45.368387
descriptionleak &mut [T] in favor of NonNull<[T]>
homepagehttps://github.com/uselessgoddess/leak_slice
repositoryhttps://github.com/uselessgoddess/leak_slice
max_upload_size
id615336
size2,450
(uselessgoddess)

documentation

README

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]);
    }
}
Commit count: 5

cargo fmt