Skip to main content

ThinSlicePtr

Struct ThinSlicePtr 

Source
pub struct ThinSlicePtr<'a, T> { /* private fields */ }
Expand description

Conceptually equivalent to &'a [T] but with length information cut out for performance reasons.

Because this type does not store the length of the slice, it is unable to do any sort of bounds checking. As such, only Self::get_unchecked() is available for indexing into the slice, where the user is responsible for checking the bounds.

When compiled in debug mode (#[cfg(debug_assertion)]), this type will store the length of the slice and perform bounds checking in Self::get_unchecked().

§Example

let slice: &[u32] = &[2, 4, 8];
let thin_slice = ThinSlicePtr::from(slice);

assert_eq!(*unsafe { thin_slice.get_unchecked(0) }, 2);
assert_eq!(*unsafe { thin_slice.get_unchecked(1) }, 4);
assert_eq!(*unsafe { thin_slice.get_unchecked(2) }, 8);

Implementations§

Source§

impl<'a, T> ThinSlicePtr<'a, T>

Source

pub unsafe fn get_unchecked(&self, index: usize) -> &'a T

Indexes the slice without performing bounds checks.

§Safety

index must be in-bounds.

Source

pub unsafe fn as_slice_unchecked(&self, len: usize) -> &'a [T]

Returns a slice without performing bounds checks.

§Safety
  • There must be no mutable aliases for the lifetime 'a to the slice. to the slice.
  • len must be less than or equal to the length of the slice.
Source

pub unsafe fn get(self, index: usize) -> &'a T

👎Deprecated since 0.18.0:

use get_unchecked() instead

Indexes the slice without performing bounds checks.

§Safety

index must be in-bounds.

Source§

impl<'a, T> ThinSlicePtr<'a, UnsafeCell<T>>

Source

pub unsafe fn as_mut_slice_unchecked(&self, len: usize) -> &'a mut [T]

Returns a mutable reference of the slice

§Safety
  • There must not be any aliases for the lifetime 'a to the slice.
  • len must be less than or equal to the length of the slice.
Source

pub fn cast(&self) -> ThinSlicePtr<'a, T>

Returns a slice pointer to the underlying type T.

Trait Implementations§

Source§

impl<'a, T> Clone for ThinSlicePtr<'a, T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a, T> Copy for ThinSlicePtr<'a, T>

Source§

impl<'a, T> From<&'a [T]> for ThinSlicePtr<'a, T>

Source§

fn from(slice: &'a [T]) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a, T> !Send for ThinSlicePtr<'a, T>

§

impl<'a, T> !Sync for ThinSlicePtr<'a, T>

§

impl<'a, T> Freeze for ThinSlicePtr<'a, T>

§

impl<'a, T> RefUnwindSafe for ThinSlicePtr<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Unpin for ThinSlicePtr<'a, T>

§

impl<'a, T> UnsafeUnpin for ThinSlicePtr<'a, T>

§

impl<'a, T> UnwindSafe for ThinSlicePtr<'a, 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, 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.