Crates.io | leak_slice |
lib.rs | leak_slice |
version | 0.2.0 |
source | src |
created_at | 2022-06-29 09:24:46.995952 |
updated_at | 2022-06-29 20:00:45.368387 |
description | leak &mut [T] in favor of NonNull<[T]> |
homepage | https://github.com/uselessgoddess/leak_slice |
repository | https://github.com/uselessgoddess/leak_slice |
max_upload_size | |
id | 615336 |
size | 2,450 |
&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]);
}
}