pub struct Clamp<Idx>(pub Idx);🔬This is a nightly-only experimental API. (
sliceindex_wrappers #146179)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 #146179)Trait Implementations§
Source§impl<T> SliceIndex<[T]> for Clamp<Range<usize>>
impl<T> SliceIndex<[T]> for Clamp<Range<usize>>
Source§fn get(self, slice: &[T]) -> Option<&Self::Output>
fn get(self, slice: &[T]) -> Option<&Self::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 Self::Output>
fn get_mut(self, slice: &mut [T]) -> Option<&mut Self::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 Self::Output
unsafe fn get_unchecked(self, slice: *const [T]) -> *const Self::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 Self::Output
unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut Self::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§impl<T> SliceIndex<[T]> for Clamp<Range<usize>>
impl<T> SliceIndex<[T]> for Clamp<Range<usize>>
Source§fn get(self, slice: &[T]) -> Option<&Self::Output>
fn get(self, slice: &[T]) -> Option<&Self::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 Self::Output>
fn get_mut(self, slice: &mut [T]) -> Option<&mut Self::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 Self::Output
unsafe fn get_unchecked(self, slice: *const [T]) -> *const Self::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 Self::Output
unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut Self::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§impl<T> SliceIndex<[T]> for Clamp<RangeFrom<usize>>
impl<T> SliceIndex<[T]> for Clamp<RangeFrom<usize>>
Source§fn get(self, slice: &[T]) -> Option<&Self::Output>
fn get(self, slice: &[T]) -> Option<&Self::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 Self::Output>
fn get_mut(self, slice: &mut [T]) -> Option<&mut Self::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 Self::Output
unsafe fn get_unchecked(self, slice: *const [T]) -> *const Self::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 Self::Output
unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut Self::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§impl<T> SliceIndex<[T]> for Clamp<RangeFrom<usize>>
impl<T> SliceIndex<[T]> for Clamp<RangeFrom<usize>>
Source§fn get(self, slice: &[T]) -> Option<&Self::Output>
fn get(self, slice: &[T]) -> Option<&Self::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 Self::Output>
fn get_mut(self, slice: &mut [T]) -> Option<&mut Self::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 Self::Output
unsafe fn get_unchecked(self, slice: *const [T]) -> *const Self::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 Self::Output
unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut Self::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§impl<T> SliceIndex<[T]> for Clamp<RangeFull>
impl<T> SliceIndex<[T]> for Clamp<RangeFull>
Source§fn get(self, slice: &[T]) -> Option<&Self::Output>
fn get(self, slice: &[T]) -> Option<&Self::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 Self::Output>
fn get_mut(self, slice: &mut [T]) -> Option<&mut Self::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 Self::Output
unsafe fn get_unchecked(self, slice: *const [T]) -> *const Self::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 Self::Output
unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut Self::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§impl<T> SliceIndex<[T]> for Clamp<RangeInclusive<usize>>
impl<T> SliceIndex<[T]> for Clamp<RangeInclusive<usize>>
Source§fn get(self, slice: &[T]) -> Option<&Self::Output>
fn get(self, slice: &[T]) -> Option<&Self::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 Self::Output>
fn get_mut(self, slice: &mut [T]) -> Option<&mut Self::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 Self::Output
unsafe fn get_unchecked(self, slice: *const [T]) -> *const Self::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 Self::Output
unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut Self::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§impl<T> SliceIndex<[T]> for Clamp<RangeInclusive<usize>>
impl<T> SliceIndex<[T]> for Clamp<RangeInclusive<usize>>
Source§fn get(self, slice: &[T]) -> Option<&Self::Output>
fn get(self, slice: &[T]) -> Option<&Self::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 Self::Output>
fn get_mut(self, slice: &mut [T]) -> Option<&mut Self::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 Self::Output
unsafe fn get_unchecked(self, slice: *const [T]) -> *const Self::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 Self::Output
unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut Self::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§impl<T> SliceIndex<[T]> for Clamp<RangeTo<usize>>
impl<T> SliceIndex<[T]> for Clamp<RangeTo<usize>>
Source§fn get(self, slice: &[T]) -> Option<&Self::Output>
fn get(self, slice: &[T]) -> Option<&Self::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 Self::Output>
fn get_mut(self, slice: &mut [T]) -> Option<&mut Self::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 Self::Output
unsafe fn get_unchecked(self, slice: *const [T]) -> *const Self::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 Self::Output
unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut Self::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§impl<T> SliceIndex<[T]> for Clamp<RangeToInclusive<usize>>
impl<T> SliceIndex<[T]> for Clamp<RangeToInclusive<usize>>
Source§fn get(self, slice: &[T]) -> Option<&Self::Output>
fn get(self, slice: &[T]) -> Option<&Self::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 Self::Output>
fn get_mut(self, slice: &mut [T]) -> Option<&mut Self::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 Self::Output
unsafe fn get_unchecked(self, slice: *const [T]) -> *const Self::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 Self::Output
unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut Self::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§impl<T> SliceIndex<[T]> for Clamp<RangeToInclusive<usize>>
impl<T> SliceIndex<[T]> for Clamp<RangeToInclusive<usize>>
Source§fn get(self, slice: &[T]) -> Option<&Self::Output>
fn get(self, slice: &[T]) -> Option<&Self::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 Self::Output>
fn get_mut(self, slice: &mut [T]) -> Option<&mut Self::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 Self::Output
unsafe fn get_unchecked(self, slice: *const [T]) -> *const Self::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 Self::Output
unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut Self::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§impl<T> SliceIndex<[T]> for Clamp<usize>
impl<T> SliceIndex<[T]> for Clamp<usize>
Source§fn get(self, slice: &[T]) -> Option<&Self::Output>
fn get(self, slice: &[T]) -> Option<&Self::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 Self::Output>
fn get_mut(self, slice: &mut [T]) -> Option<&mut Self::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 Self::Output
unsafe fn get_unchecked(self, slice: *const [T]) -> *const Self::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 Self::Output
unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut Self::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
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> 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