3个不稳定版本
0.2.0 | 2022年6月29日 |
---|---|
0.1.1 | 2022年6月29日 |
0.1.0 | 2022年6月29日 |
#566 in 内存管理
在2个Crate中使用(通过doublets)
3KB
建议使用&mut [T]
代替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]);
}
}