orx-split-vec 3.8.0

An efficient constant access time vector with dynamic capacity and pinned elements.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::Fragment;
use alloc::vec::Vec;
use core::mem::ManuallyDrop;

pub fn fragment_into_raw<T>(mut fragment: Fragment<T>) -> (*mut T, usize, usize) {
    let (len, capacity) = (fragment.len(), fragment.capacity());
    let ptr = fragment.as_mut_ptr();

    let _ = ManuallyDrop::new(fragment);

    (ptr, len, capacity)
}

pub unsafe fn fragment_from_raw<T>(ptr: *mut T, len: usize, capacity: usize) -> Fragment<T> {
    assert!(capacity >= len);
    let vec = Vec::from_raw_parts(ptr, len, capacity);
    vec.into()
}