Struct Slice

Source
#[repr(C)]
pub struct Slice<T> { /* private fields */ }
Expand description

A C compatible slice of type T

Implementations§

Source§

impl<T> Slice<T>

Source

pub const unsafe fn from_raw_parts(ptr: *mut T, len: usize) -> Slice<T>

Source

pub const fn from_slice_mut(slice: &mut [T]) -> Slice<T>

Source

pub const fn from_slice(slice: &[T]) -> Slice<T>

Source

pub const fn len(&self) -> usize

Source

pub const fn as_ptr(&self) -> *const T

Source

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

Source

pub const unsafe fn as_slice_unchecked<'a>(&self) -> &'a [T]

Source

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

Source

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

Source

pub unsafe fn try_as_slice_mut<'a>( &self, ) -> Result<&'a mut [T], InvalidSliceError>

Source

pub unsafe fn try_as_slice<'a>(&self) -> Result<&'a [T], InvalidSliceError>

Source§

impl<T> Slice<Slice<T>>

Source

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 is the same as &[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

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 is the same as &[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>

Source

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

Source

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

Trait Implementations§

Source§

impl<T> Clone for Slice<T>
where T: Clone,

Source§

fn clone(&self) -> Slice<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Slice<T>
where T: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T> NotZeroable for Slice<T>

Source§

fn is_zero(&self) -> bool

Source§

impl<T> Copy for Slice<T>
where T: Copy,

Auto Trait Implementations§

§

impl<T> Freeze for Slice<T>

§

impl<T> RefUnwindSafe for Slice<T>
where T: RefUnwindSafe,

§

impl<T> !Send for Slice<T>

§

impl<T> !Sync for Slice<T>

§

impl<T> Unpin for Slice<T>

§

impl<T> UnwindSafe for Slice<T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.