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>
impl<'a, T> ThinSlicePtr<'a, T>
Sourcepub unsafe fn get_unchecked(&self, index: usize) -> &'a T
pub unsafe fn get_unchecked(&self, index: usize) -> &'a T
Sourcepub unsafe fn as_slice_unchecked(&self, len: usize) -> &'a [T]
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
'ato the slice. to the slice. lenmust be less than or equal to the length of the slice.
Source§impl<'a, T> ThinSlicePtr<'a, UnsafeCell<T>>
impl<'a, T> ThinSlicePtr<'a, UnsafeCell<T>>
Sourcepub unsafe fn as_mut_slice_unchecked(&self, len: usize) -> &'a mut [T]
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
'ato the slice. lenmust be less than or equal to the length of the slice.
Sourcepub fn cast(&self) -> ThinSlicePtr<'a, T>
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>
impl<'a, T> Clone for ThinSlicePtr<'a, T>
impl<'a, T> Copy for ThinSlicePtr<'a, T>
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> 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