Clamp

Struct Clamp 

Source
pub struct Clamp<Idx>(pub Idx);
🔬This is a nightly-only experimental API. (sliceindex_wrappers)
Expand description

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..)]);

Tuple Fields§

§0: Idx
🔬This is a nightly-only experimental API. (sliceindex_wrappers)

Trait Implementations§

Source§

impl<Idx> Debug for Clamp<Idx>
where Idx: Debug,

Source§

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

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

impl<T> SliceIndex<[T]> for Clamp<Range<usize>>

Source§

type Output = [T]

The output type returned by methods.
Source§

fn get( self, slice: &[T], ) -> Option<&<Clamp<Range<usize>> as SliceIndex<[T]>>::Output>

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a shared reference to the output at this location, if in bounds.
Source§

fn get_mut( self, slice: &mut [T], ) -> Option<&mut <Clamp<Range<usize>> as SliceIndex<[T]>>::Output>

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable reference to the output at this location, if in bounds.
Source§

unsafe fn get_unchecked( self, slice: *const [T], ) -> *const <Clamp<Range<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a pointer to the output at this location, without performing any bounds checking. Read more
Source§

unsafe fn get_unchecked_mut( self, slice: *mut [T], ) -> *mut <Clamp<Range<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable pointer to the output at this location, without performing any bounds checking. Read more
Source§

fn index(self, slice: &[T]) -> &<Clamp<Range<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a shared reference to the output at this location, panicking if out of bounds.
Source§

fn index_mut( self, slice: &mut [T], ) -> &mut <Clamp<Range<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable reference to the output at this location, panicking if out of bounds.
Source§

impl<T> SliceIndex<[T]> for Clamp<Range<usize>>

Source§

type Output = [T]

The output type returned by methods.
Source§

fn get( self, slice: &[T], ) -> Option<&<Clamp<Range<usize>> as SliceIndex<[T]>>::Output>

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a shared reference to the output at this location, if in bounds.
Source§

fn get_mut( self, slice: &mut [T], ) -> Option<&mut <Clamp<Range<usize>> as SliceIndex<[T]>>::Output>

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable reference to the output at this location, if in bounds.
Source§

unsafe fn get_unchecked( self, slice: *const [T], ) -> *const <Clamp<Range<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a pointer to the output at this location, without performing any bounds checking. Read more
Source§

unsafe fn get_unchecked_mut( self, slice: *mut [T], ) -> *mut <Clamp<Range<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable pointer to the output at this location, without performing any bounds checking. Read more
Source§

fn index(self, slice: &[T]) -> &<Clamp<Range<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a shared reference to the output at this location, panicking if out of bounds.
Source§

fn index_mut( self, slice: &mut [T], ) -> &mut <Clamp<Range<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable reference to the output at this location, panicking if out of bounds.
Source§

impl<T> SliceIndex<[T]> for Clamp<RangeFrom<usize>>

Source§

type Output = [T]

The output type returned by methods.
Source§

fn get( self, slice: &[T], ) -> Option<&<Clamp<RangeFrom<usize>> as SliceIndex<[T]>>::Output>

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a shared reference to the output at this location, if in bounds.
Source§

fn get_mut( self, slice: &mut [T], ) -> Option<&mut <Clamp<RangeFrom<usize>> as SliceIndex<[T]>>::Output>

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable reference to the output at this location, if in bounds.
Source§

unsafe fn get_unchecked( self, slice: *const [T], ) -> *const <Clamp<RangeFrom<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a pointer to the output at this location, without performing any bounds checking. Read more
Source§

unsafe fn get_unchecked_mut( self, slice: *mut [T], ) -> *mut <Clamp<RangeFrom<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable pointer to the output at this location, without performing any bounds checking. Read more
Source§

fn index( self, slice: &[T], ) -> &<Clamp<RangeFrom<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a shared reference to the output at this location, panicking if out of bounds.
Source§

fn index_mut( self, slice: &mut [T], ) -> &mut <Clamp<RangeFrom<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable reference to the output at this location, panicking if out of bounds.
Source§

impl<T> SliceIndex<[T]> for Clamp<RangeFrom<usize>>

Source§

type Output = [T]

The output type returned by methods.
Source§

fn get( self, slice: &[T], ) -> Option<&<Clamp<RangeFrom<usize>> as SliceIndex<[T]>>::Output>

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a shared reference to the output at this location, if in bounds.
Source§

fn get_mut( self, slice: &mut [T], ) -> Option<&mut <Clamp<RangeFrom<usize>> as SliceIndex<[T]>>::Output>

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable reference to the output at this location, if in bounds.
Source§

unsafe fn get_unchecked( self, slice: *const [T], ) -> *const <Clamp<RangeFrom<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a pointer to the output at this location, without performing any bounds checking. Read more
Source§

unsafe fn get_unchecked_mut( self, slice: *mut [T], ) -> *mut <Clamp<RangeFrom<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable pointer to the output at this location, without performing any bounds checking. Read more
Source§

fn index( self, slice: &[T], ) -> &<Clamp<RangeFrom<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a shared reference to the output at this location, panicking if out of bounds.
Source§

fn index_mut( self, slice: &mut [T], ) -> &mut <Clamp<RangeFrom<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable reference to the output at this location, panicking if out of bounds.
Source§

impl<T> SliceIndex<[T]> for Clamp<RangeFull>

Source§

type Output = [T]

The output type returned by methods.
Source§

fn get( self, slice: &[T], ) -> Option<&<Clamp<RangeFull> as SliceIndex<[T]>>::Output>

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a shared reference to the output at this location, if in bounds.
Source§

fn get_mut( self, slice: &mut [T], ) -> Option<&mut <Clamp<RangeFull> as SliceIndex<[T]>>::Output>

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable reference to the output at this location, if in bounds.
Source§

unsafe fn get_unchecked( self, slice: *const [T], ) -> *const <Clamp<RangeFull> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a pointer to the output at this location, without performing any bounds checking. Read more
Source§

unsafe fn get_unchecked_mut( self, slice: *mut [T], ) -> *mut <Clamp<RangeFull> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable pointer to the output at this location, without performing any bounds checking. Read more
Source§

fn index(self, slice: &[T]) -> &<Clamp<RangeFull> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a shared reference to the output at this location, panicking if out of bounds.
Source§

fn index_mut( self, slice: &mut [T], ) -> &mut <Clamp<RangeFull> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable reference to the output at this location, panicking if out of bounds.
Source§

impl<T> SliceIndex<[T]> for Clamp<RangeInclusive<usize>>

Source§

type Output = [T]

The output type returned by methods.
Source§

fn get( self, slice: &[T], ) -> Option<&<Clamp<RangeInclusive<usize>> as SliceIndex<[T]>>::Output>

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a shared reference to the output at this location, if in bounds.
Source§

fn get_mut( self, slice: &mut [T], ) -> Option<&mut <Clamp<RangeInclusive<usize>> as SliceIndex<[T]>>::Output>

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable reference to the output at this location, if in bounds.
Source§

unsafe fn get_unchecked( self, slice: *const [T], ) -> *const <Clamp<RangeInclusive<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a pointer to the output at this location, without performing any bounds checking. Read more
Source§

unsafe fn get_unchecked_mut( self, slice: *mut [T], ) -> *mut <Clamp<RangeInclusive<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable pointer to the output at this location, without performing any bounds checking. Read more
Source§

fn index( self, slice: &[T], ) -> &<Clamp<RangeInclusive<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a shared reference to the output at this location, panicking if out of bounds.
Source§

fn index_mut( self, slice: &mut [T], ) -> &mut <Clamp<RangeInclusive<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable reference to the output at this location, panicking if out of bounds.
Source§

impl<T> SliceIndex<[T]> for Clamp<RangeInclusive<usize>>

Source§

type Output = [T]

The output type returned by methods.
Source§

fn get( self, slice: &[T], ) -> Option<&<Clamp<RangeInclusive<usize>> as SliceIndex<[T]>>::Output>

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a shared reference to the output at this location, if in bounds.
Source§

fn get_mut( self, slice: &mut [T], ) -> Option<&mut <Clamp<RangeInclusive<usize>> as SliceIndex<[T]>>::Output>

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable reference to the output at this location, if in bounds.
Source§

unsafe fn get_unchecked( self, slice: *const [T], ) -> *const <Clamp<RangeInclusive<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a pointer to the output at this location, without performing any bounds checking. Read more
Source§

unsafe fn get_unchecked_mut( self, slice: *mut [T], ) -> *mut <Clamp<RangeInclusive<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable pointer to the output at this location, without performing any bounds checking. Read more
Source§

fn index( self, slice: &[T], ) -> &<Clamp<RangeInclusive<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a shared reference to the output at this location, panicking if out of bounds.
Source§

fn index_mut( self, slice: &mut [T], ) -> &mut <Clamp<RangeInclusive<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable reference to the output at this location, panicking if out of bounds.
Source§

impl<T> SliceIndex<[T]> for Clamp<RangeTo<usize>>

Source§

type Output = [T]

The output type returned by methods.
Source§

fn get( self, slice: &[T], ) -> Option<&<Clamp<RangeTo<usize>> as SliceIndex<[T]>>::Output>

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a shared reference to the output at this location, if in bounds.
Source§

fn get_mut( self, slice: &mut [T], ) -> Option<&mut <Clamp<RangeTo<usize>> as SliceIndex<[T]>>::Output>

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable reference to the output at this location, if in bounds.
Source§

unsafe fn get_unchecked( self, slice: *const [T], ) -> *const <Clamp<RangeTo<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a pointer to the output at this location, without performing any bounds checking. Read more
Source§

unsafe fn get_unchecked_mut( self, slice: *mut [T], ) -> *mut <Clamp<RangeTo<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable pointer to the output at this location, without performing any bounds checking. Read more
Source§

fn index( self, slice: &[T], ) -> &<Clamp<RangeTo<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a shared reference to the output at this location, panicking if out of bounds.
Source§

fn index_mut( self, slice: &mut [T], ) -> &mut <Clamp<RangeTo<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable reference to the output at this location, panicking if out of bounds.
Source§

impl<T> SliceIndex<[T]> for Clamp<RangeToInclusive<usize>>

Source§

type Output = [T]

The output type returned by methods.
Source§

fn get( self, slice: &[T], ) -> Option<&<Clamp<RangeToInclusive<usize>> as SliceIndex<[T]>>::Output>

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a shared reference to the output at this location, if in bounds.
Source§

fn get_mut( self, slice: &mut [T], ) -> Option<&mut <Clamp<RangeToInclusive<usize>> as SliceIndex<[T]>>::Output>

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable reference to the output at this location, if in bounds.
Source§

unsafe fn get_unchecked( self, slice: *const [T], ) -> *const <Clamp<RangeToInclusive<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a pointer to the output at this location, without performing any bounds checking. Read more
Source§

unsafe fn get_unchecked_mut( self, slice: *mut [T], ) -> *mut <Clamp<RangeToInclusive<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable pointer to the output at this location, without performing any bounds checking. Read more
Source§

fn index( self, slice: &[T], ) -> &<Clamp<RangeToInclusive<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a shared reference to the output at this location, panicking if out of bounds.
Source§

fn index_mut( self, slice: &mut [T], ) -> &mut <Clamp<RangeToInclusive<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable reference to the output at this location, panicking if out of bounds.
Source§

impl<T> SliceIndex<[T]> for Clamp<RangeToInclusive<usize>>

Source§

type Output = [T]

The output type returned by methods.
Source§

fn get( self, slice: &[T], ) -> Option<&<Clamp<RangeToInclusive<usize>> as SliceIndex<[T]>>::Output>

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a shared reference to the output at this location, if in bounds.
Source§

fn get_mut( self, slice: &mut [T], ) -> Option<&mut <Clamp<RangeToInclusive<usize>> as SliceIndex<[T]>>::Output>

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable reference to the output at this location, if in bounds.
Source§

unsafe fn get_unchecked( self, slice: *const [T], ) -> *const <Clamp<RangeToInclusive<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a pointer to the output at this location, without performing any bounds checking. Read more
Source§

unsafe fn get_unchecked_mut( self, slice: *mut [T], ) -> *mut <Clamp<RangeToInclusive<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable pointer to the output at this location, without performing any bounds checking. Read more
Source§

fn index( self, slice: &[T], ) -> &<Clamp<RangeToInclusive<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a shared reference to the output at this location, panicking if out of bounds.
Source§

fn index_mut( self, slice: &mut [T], ) -> &mut <Clamp<RangeToInclusive<usize>> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable reference to the output at this location, panicking if out of bounds.
Source§

impl<T> SliceIndex<[T]> for Clamp<usize>

Source§

type Output = T

The output type returned by methods.
Source§

fn get(self, slice: &[T]) -> Option<&<Clamp<usize> as SliceIndex<[T]>>::Output>

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a shared reference to the output at this location, if in bounds.
Source§

fn get_mut( self, slice: &mut [T], ) -> Option<&mut <Clamp<usize> as SliceIndex<[T]>>::Output>

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable reference to the output at this location, if in bounds.
Source§

unsafe fn get_unchecked( self, slice: *const [T], ) -> *const <Clamp<usize> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a pointer to the output at this location, without performing any bounds checking. Read more
Source§

unsafe fn get_unchecked_mut( self, slice: *mut [T], ) -> *mut <Clamp<usize> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable pointer to the output at this location, without performing any bounds checking. Read more
Source§

fn index(self, slice: &[T]) -> &<Clamp<usize> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a shared reference to the output at this location, panicking if out of bounds.
Source§

fn index_mut( self, slice: &mut [T], ) -> &mut <Clamp<usize> as SliceIndex<[T]>>::Output

🔬This is a nightly-only experimental API. (slice_index_methods)
Returns a mutable reference to the output at this location, panicking if out of bounds.

Auto Trait Implementations§

§

impl<Idx> Freeze for Clamp<Idx>
where Idx: Freeze,

§

impl<Idx> RefUnwindSafe for Clamp<Idx>
where Idx: RefUnwindSafe,

§

impl<Idx> Send for Clamp<Idx>
where Idx: Send,

§

impl<Idx> Sync for Clamp<Idx>
where Idx: Sync,

§

impl<Idx> Unpin for Clamp<Idx>
where Idx: Unpin,

§

impl<Idx> UnwindSafe for Clamp<Idx>
where Idx: UnwindSafe,

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> 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.