#[repr(C)]pub struct ExternalSlice<T: 'static> {
ptr: NonNull<T>,
len: usize,
capacity: usize,
}Expand description
A slice stored as a standalone struct, suitable for wrapping in ExternalPtr.
This is analogous to the data inside a Box<[T]>, but stores capacity
for proper deallocation when created from a Vec.
§Usage
To use with ExternalPtr, implement TypedExternal for your specific
ExternalSlice<YourType>:
ⓘ
impl_typed_external!(ExternalSlice<MyElement>);
let ptr = ExternalPtr::new(ExternalSlice::new(vec![1, 2, 3]));Fields§
§ptr: NonNull<T>§len: usize§capacity: usizeImplementations§
Source§impl<T: 'static> ExternalSlice<T>
impl<T: 'static> ExternalSlice<T>
Sourcepub fn new(slice: Vec<T>) -> Self
pub fn new(slice: Vec<T>) -> Self
Create an external slice from a Vec, preserving its allocation.
Sourcepub fn from_boxed(boxed: Box<[T]>) -> Self
pub fn from_boxed(boxed: Box<[T]>) -> Self
Create from a boxed slice (capacity == len).
Sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Borrow the contents as a mutable slice.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for ExternalSlice<T>
impl<T> RefUnwindSafe for ExternalSlice<T>where
T: RefUnwindSafe,
impl<T> !Send for ExternalSlice<T>
impl<T> !Sync for ExternalSlice<T>
impl<T> Unpin for ExternalSlice<T>
impl<T> UnsafeUnpin for ExternalSlice<T>
impl<T> UnwindSafe for ExternalSlice<T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more