Struct Clamp

struct Clamp<Idx>(11915)

Clamps an index, guaranteeing that it will only access valid elements of the slice.

Examples

#![feature(sliceindex_wrappers)]

use core::index::Clamp;

let s: &[usize] = &[0, 1, 2, 3];

assert_eq!(&3, &s[Clamp(6)]);
assert_eq!(&[1, 2, 3], &s[Clamp(1..6)]);
assert_eq!(&[] as &[usize], &s[Clamp(5..6)]);
assert_eq!(&[0, 1, 2, 3], &s[Clamp(..6)]);
assert_eq!(&[0, 1, 2, 3], &s[Clamp(..=6)]);
assert_eq!(&[] as &[usize], &s[Clamp(6..)]);

Implementations

impl<Idx> Freeze for Clamp<Idx>

impl<Idx> RefUnwindSafe for Clamp<Idx>

impl<Idx> Send for Clamp<Idx>

impl<Idx> Sync for Clamp<Idx>

impl<Idx> Unpin for Clamp<Idx>

impl<Idx> UnwindSafe for Clamp<Idx>

impl<Idx: $crate::fmt::Debug> Debug for Clamp<Idx>

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

impl<T> Any for Clamp<Idx>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Clamp<Idx>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Clamp<Idx>

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

impl<T> From for Clamp<Idx>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> SliceIndex for Clamp<ops::Range<usize>>

fn get(self: Self, slice: &[T]) -> Option<&<Self as >::Output>
fn get_mut(self: Self, slice: &mut [T]) -> Option<&mut <Self as >::Output>
unsafe fn get_unchecked(self: Self, slice: *const [T]) -> *const <Self as >::Output
unsafe fn get_unchecked_mut(self: Self, slice: *mut [T]) -> *mut <Self as >::Output
fn index(self: Self, slice: &[T]) -> &<Self as >::Output
fn index_mut(self: Self, slice: &mut [T]) -> &mut <Self as >::Output

impl<T> SliceIndex for Clamp<ops::RangeFrom<usize>>

fn get(self: Self, slice: &[T]) -> Option<&<Self as >::Output>
fn get_mut(self: Self, slice: &mut [T]) -> Option<&mut <Self as >::Output>
unsafe fn get_unchecked(self: Self, slice: *const [T]) -> *const <Self as >::Output
unsafe fn get_unchecked_mut(self: Self, slice: *mut [T]) -> *mut <Self as >::Output
fn index(self: Self, slice: &[T]) -> &<Self as >::Output
fn index_mut(self: Self, slice: &mut [T]) -> &mut <Self as >::Output

impl<T> SliceIndex for Clamp<range::RangeFull>

fn get(self: Self, slice: &[T]) -> Option<&<Self as >::Output>
fn get_mut(self: Self, slice: &mut [T]) -> Option<&mut <Self as >::Output>
unsafe fn get_unchecked(self: Self, slice: *const [T]) -> *const <Self as >::Output
unsafe fn get_unchecked_mut(self: Self, slice: *mut [T]) -> *mut <Self as >::Output
fn index(self: Self, slice: &[T]) -> &<Self as >::Output
fn index_mut(self: Self, slice: &mut [T]) -> &mut <Self as >::Output

impl<T> SliceIndex for Clamp<ops::RangeInclusive<usize>>

fn get(self: Self, slice: &[T]) -> Option<&<Self as >::Output>
fn get_mut(self: Self, slice: &mut [T]) -> Option<&mut <Self as >::Output>
unsafe fn get_unchecked(self: Self, slice: *const [T]) -> *const <Self as >::Output
unsafe fn get_unchecked_mut(self: Self, slice: *mut [T]) -> *mut <Self as >::Output
fn index(self: Self, slice: &[T]) -> &<Self as >::Output
fn index_mut(self: Self, slice: &mut [T]) -> &mut <Self as >::Output

impl<T> SliceIndex for Clamp<range::RangeTo<usize>>

fn get(self: Self, slice: &[T]) -> Option<&<Self as >::Output>
fn get_mut(self: Self, slice: &mut [T]) -> Option<&mut <Self as >::Output>
unsafe fn get_unchecked(self: Self, slice: *const [T]) -> *const <Self as >::Output
unsafe fn get_unchecked_mut(self: Self, slice: *mut [T]) -> *mut <Self as >::Output
fn index(self: Self, slice: &[T]) -> &<Self as >::Output
fn index_mut(self: Self, slice: &mut [T]) -> &mut <Self as >::Output

impl<T> SliceIndex for Clamp<ops::RangeToInclusive<usize>>

fn get(self: Self, slice: &[T]) -> Option<&<Self as >::Output>
fn get_mut(self: Self, slice: &mut [T]) -> Option<&mut <Self as >::Output>
unsafe fn get_unchecked(self: Self, slice: *const [T]) -> *const <Self as >::Output
unsafe fn get_unchecked_mut(self: Self, slice: *mut [T]) -> *mut <Self as >::Output
fn index(self: Self, slice: &[T]) -> &<Self as >::Output
fn index_mut(self: Self, slice: &mut [T]) -> &mut <Self as >::Output

impl<T> SliceIndex for Clamp<range::Range<usize>>

fn get(self: Self, slice: &[T]) -> Option<&<Self as >::Output>
fn get_mut(self: Self, slice: &mut [T]) -> Option<&mut <Self as >::Output>
unsafe fn get_unchecked(self: Self, slice: *const [T]) -> *const <Self as >::Output
unsafe fn get_unchecked_mut(self: Self, slice: *mut [T]) -> *mut <Self as >::Output
fn index(self: Self, slice: &[T]) -> &<Self as >::Output
fn index_mut(self: Self, slice: &mut [T]) -> &mut <Self as >::Output

impl<T> SliceIndex for Clamp<range::RangeFrom<usize>>

fn get(self: Self, slice: &[T]) -> Option<&<Self as >::Output>
fn get_mut(self: Self, slice: &mut [T]) -> Option<&mut <Self as >::Output>
unsafe fn get_unchecked(self: Self, slice: *const [T]) -> *const <Self as >::Output
unsafe fn get_unchecked_mut(self: Self, slice: *mut [T]) -> *mut <Self as >::Output
fn index(self: Self, slice: &[T]) -> &<Self as >::Output
fn index_mut(self: Self, slice: &mut [T]) -> &mut <Self as >::Output

impl<T> SliceIndex for Clamp<range::RangeInclusive<usize>>

fn get(self: Self, slice: &[T]) -> Option<&<Self as >::Output>
fn get_mut(self: Self, slice: &mut [T]) -> Option<&mut <Self as >::Output>
unsafe fn get_unchecked(self: Self, slice: *const [T]) -> *const <Self as >::Output
unsafe fn get_unchecked_mut(self: Self, slice: *mut [T]) -> *mut <Self as >::Output
fn index(self: Self, slice: &[T]) -> &<Self as >::Output
fn index_mut(self: Self, slice: &mut [T]) -> &mut <Self as >::Output

impl<T> SliceIndex for Clamp<range::RangeToInclusive<usize>>

fn get(self: Self, slice: &[T]) -> Option<&<Self as >::Output>
fn get_mut(self: Self, slice: &mut [T]) -> Option<&mut <Self as >::Output>
unsafe fn get_unchecked(self: Self, slice: *const [T]) -> *const <Self as >::Output
unsafe fn get_unchecked_mut(self: Self, slice: *mut [T]) -> *mut <Self as >::Output
fn index(self: Self, slice: &[T]) -> &<Self as >::Output
fn index_mut(self: Self, slice: &mut [T]) -> &mut <Self as >::Output

impl<T> SliceIndex for Clamp<usize>

fn get(self: Self, slice: &[T]) -> Option<&<Self as >::Output>
fn get_mut(self: Self, slice: &mut [T]) -> Option<&mut <Self as >::Output>
unsafe fn get_unchecked(self: Self, slice: *const [T]) -> *const <Self as >::Output
unsafe fn get_unchecked_mut(self: Self, slice: *mut [T]) -> *mut <Self as >::Output
fn index(self: Self, slice: &[T]) -> &<Self as >::Output
fn index_mut(self: Self, slice: &mut [T]) -> &mut <Self as >::Output

impl<T, U> Into for Clamp<Idx>

fn into(self: Self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom for Clamp<Idx>

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

impl<T, U> TryInto for Clamp<Idx>

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