pub struct Slice<T> { /* private fields */ }Expand description
A C compatible slice of type T
Implementations§
Source§impl<T> Slice<T>
impl<T> Slice<T>
pub const unsafe fn from_raw_parts(ptr: *mut T, len: usize) -> Slice<T>
pub const fn from_slice_mut(slice: &mut [T]) -> Slice<T>
pub const fn from_slice(slice: &[T]) -> Slice<T>
pub const fn len(&self) -> usize
pub const fn as_ptr(&self) -> *const T
Sourcepub const unsafe fn as_slice_mut_unchecked<'a>(&self) -> &'a mut [T]
pub const unsafe fn as_slice_mut_unchecked<'a>(&self) -> &'a mut [T]
Converts an FFI [RawSlice<T>] into a raw rust slice of type T
pub const unsafe fn as_slice_unchecked<'a>(&self) -> &'a [T]
Sourcepub unsafe fn try_as_slice_mut_custom<'a>(
&self,
validator: impl FnOnce(*const ()) -> bool,
) -> Result<&'a mut [T], InvalidSliceError>
pub unsafe fn try_as_slice_mut_custom<'a>( &self, validator: impl FnOnce(*const ()) -> bool, ) -> Result<&'a mut [T], InvalidSliceError>
Attempts to convert an FFI [RawSlice<T>] into a raw rust slice of type T, running the pointer into a custom validator function
returns Err(InvalidSliceError) if the slice doesn’t pass the rust slice requirements or returns Err(InvalidSliceError::Other) if the validator function returns false
Sourcepub unsafe fn try_as_slice_custom<'a>(
&self,
validator: impl Fn(*const ()) -> bool,
) -> Result<&'a [T], InvalidSliceError>
pub unsafe fn try_as_slice_custom<'a>( &self, validator: impl Fn(*const ()) -> bool, ) -> Result<&'a [T], InvalidSliceError>
Attempts to convert an FFI [RawSlice<T>] into a raw rust slice of type T, running the pointer into a custom validator function
returns Err(InvalidSliceError) if the slice doesn’t pass the rust slice requirements or returns Err(InvalidSliceError::Other) if the validator function returns false
pub unsafe fn try_as_slice_mut<'a>( &self, ) -> Result<&'a mut [T], InvalidSliceError>
pub unsafe fn try_as_slice<'a>(&self) -> Result<&'a [T], InvalidSliceError>
Source§impl<T> Slice<Slice<T>>
impl<T> Slice<Slice<T>>
Sourcepub const unsafe fn from_slices_ptr_mut(
slices: *mut [*mut [T]],
) -> Slice<Slice<T>>
pub const unsafe fn from_slices_ptr_mut( slices: *mut [*mut [T]], ) -> Slice<Slice<T>>
Converts an FFI Slice of slices to a Rust slice of slices of type T *mut [*mut [T]].
§Safety
The given slice will be unsafely reused, for now the data will be left unchanged in the current rust version because the layout of Slice[T],
However since the layout of slices isn’t guaranteed yet by rust, this function may change the given buffer in the future, or by some obscure optimizations.
this should be solved if this RFC got accepted
Sourcepub unsafe fn try_into_slices_ptr_mut(
self,
custom_validate: impl Fn(*const ()) -> bool,
) -> Result<*mut [*mut [T]], InvalidSliceError>
pub unsafe fn try_into_slices_ptr_mut( self, custom_validate: impl Fn(*const ()) -> bool, ) -> Result<*mut [*mut [T]], InvalidSliceError>
Attempts to convert an FFI Slice of Slices into a rust slice of slices *mut [*mut [T]].
given an FFI Slice of Slices
§Safety
The given FFI slice will be unsafely reused, for now the data will be left unchanged in the current rust version because the layout of Slice[T],
However since the layout of slices isn’t guaranteed yet by rust, this function may change the given buffer in the future, or by some obscure optimizations.
this should be solved if this RFC got accepted
Source§impl Slice<Str>
impl Slice<Str>
Sourcepub const unsafe fn from_str_slices_mut(slices: *mut [*mut str]) -> Slice<Str>
pub const unsafe fn from_str_slices_mut(slices: *mut [*mut str]) -> Slice<Str>
Converts a mutable slice of string slices [*mut str] into an FFI safe Slice of Strs.
§Safety
The given slice will be unsafely reused, for now the data will be left unchanged in the current rust version because the layout of Str is the same as &str, However since the layout of slices isn’t guaranteed yet by rust, this function may change the given buffer in the future.
this should be solved if this RFC got accepted
Sourcepub unsafe fn try_into_str_slices_mut<'a>(
self,
custom_validate: impl Fn(*const ()) -> bool,
) -> Result<*mut [&'a str], InvalidStrError>
pub unsafe fn try_into_str_slices_mut<'a>( self, custom_validate: impl Fn(*const ()) -> bool, ) -> Result<*mut [&'a str], InvalidStrError>
Attempts to convert an FFI Slice of Strs into a rust slice of str slices *mut [*mut str].
given an FFI Slice of Strs
§Safety
The given FFI slice will be unsafely reused, for now the data will be left unchanged in the current rust version because the layout of Str is the same as &str, However since the layout of slices isn’t guaranteed yet by rust, this function may change the given buffer in the future, or by some obscure optimizations.
this should be solved if this RFC got accepted