Struct Clamp
pub struct Clamp<Idx>(pub Idx);
Clamps an index, guaranteeing that it will only access valid elements of the slice.
Examples
use Clamp;
let s: & = &;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Fields
0: Idx
Trait Implementations
impl<Idx: Debug> Debug for Clamp<Idx>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<T> SliceIndex<[T]> for Clamp<Range<usize>>
type Output = [T];fn get(self, slice: &[T]) -> Option<&Self::Output>fn get_mut(self, slice: &mut [T]) -> Option<&mut Self::Output>unsafe fn get_unchecked(self, slice: *const [T]) -> *const Self::Outputunsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut Self::Outputfn index(self, slice: &[T]) -> &Self::Outputfn index_mut(self, slice: &mut [T]) -> &mut Self::Output
impl<T> SliceIndex<[T]> for Clamp<Range<usize>>
type Output = [T];fn get(self, slice: &[T]) -> Option<&Self::Output>fn get_mut(self, slice: &mut [T]) -> Option<&mut Self::Output>unsafe fn get_unchecked(self, slice: *const [T]) -> *const Self::Outputunsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut Self::Outputfn index(self, slice: &[T]) -> &Self::Outputfn index_mut(self, slice: &mut [T]) -> &mut Self::Output
impl<T> SliceIndex<[T]> for Clamp<RangeFrom<usize>>
type Output = [T];fn get(self, slice: &[T]) -> Option<&Self::Output>fn get_mut(self, slice: &mut [T]) -> Option<&mut Self::Output>unsafe fn get_unchecked(self, slice: *const [T]) -> *const Self::Outputunsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut Self::Outputfn index(self, slice: &[T]) -> &Self::Outputfn index_mut(self, slice: &mut [T]) -> &mut Self::Output
impl<T> SliceIndex<[T]> for Clamp<RangeFrom<usize>>
type Output = [T];fn get(self, slice: &[T]) -> Option<&Self::Output>fn get_mut(self, slice: &mut [T]) -> Option<&mut Self::Output>unsafe fn get_unchecked(self, slice: *const [T]) -> *const Self::Outputunsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut Self::Outputfn index(self, slice: &[T]) -> &Self::Outputfn index_mut(self, slice: &mut [T]) -> &mut Self::Output
impl<T> SliceIndex<[T]> for Clamp<RangeFull>
type Output = [T];fn get(self, slice: &[T]) -> Option<&Self::Output>fn get_mut(self, slice: &mut [T]) -> Option<&mut Self::Output>unsafe fn get_unchecked(self, slice: *const [T]) -> *const Self::Outputunsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut Self::Outputfn index(self, slice: &[T]) -> &Self::Outputfn index_mut(self, slice: &mut [T]) -> &mut Self::Output
impl<T> SliceIndex<[T]> for Clamp<RangeInclusive<usize>>
type Output = [T];fn get(self, slice: &[T]) -> Option<&Self::Output>fn get_mut(self, slice: &mut [T]) -> Option<&mut Self::Output>unsafe fn get_unchecked(self, slice: *const [T]) -> *const Self::Outputunsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut Self::Outputfn index(self, slice: &[T]) -> &Self::Outputfn index_mut(self, slice: &mut [T]) -> &mut Self::Output
impl<T> SliceIndex<[T]> for Clamp<RangeInclusive<usize>>
type Output = [T];fn get(self, slice: &[T]) -> Option<&Self::Output>fn get_mut(self, slice: &mut [T]) -> Option<&mut Self::Output>unsafe fn get_unchecked(self, slice: *const [T]) -> *const Self::Outputunsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut Self::Outputfn index(self, slice: &[T]) -> &Self::Outputfn index_mut(self, slice: &mut [T]) -> &mut Self::Output
impl<T> SliceIndex<[T]> for Clamp<RangeTo<usize>>
type Output = [T];fn get(self, slice: &[T]) -> Option<&Self::Output>fn get_mut(self, slice: &mut [T]) -> Option<&mut Self::Output>unsafe fn get_unchecked(self, slice: *const [T]) -> *const Self::Outputunsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut Self::Outputfn index(self, slice: &[T]) -> &Self::Outputfn index_mut(self, slice: &mut [T]) -> &mut Self::Output
impl<T> SliceIndex<[T]> for Clamp<RangeToInclusive<usize>>
type Output = [T];fn get(self, slice: &[T]) -> Option<&Self::Output>fn get_mut(self, slice: &mut [T]) -> Option<&mut Self::Output>unsafe fn get_unchecked(self, slice: *const [T]) -> *const Self::Outputunsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut Self::Outputfn index(self, slice: &[T]) -> &Self::Outputfn index_mut(self, slice: &mut [T]) -> &mut Self::Output
impl<T> SliceIndex<[T]> for Clamp<RangeToInclusive<usize>>
type Output = [T];fn get(self, slice: &[T]) -> Option<&Self::Output>fn get_mut(self, slice: &mut [T]) -> Option<&mut Self::Output>unsafe fn get_unchecked(self, slice: *const [T]) -> *const Self::Outputunsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut Self::Outputfn index(self, slice: &[T]) -> &Self::Outputfn index_mut(self, slice: &mut [T]) -> &mut Self::Output
impl<T> SliceIndex<[T]> for Clamp<usize>
type Output = T;fn get(self, slice: &[T]) -> Option<&Self::Output>fn get_mut(self, slice: &mut [T]) -> Option<&mut Self::Output>unsafe fn get_unchecked(self, slice: *const [T]) -> *const Self::Outputunsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut Self::Outputfn index(self, slice: &[T]) -> &Self::Outputfn index_mut(self, slice: &mut [T]) -> &mut Self::Output
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> UnsafeUnpin for Clamp<Idx>
where
Idx: UnsafeUnpin,
impl<Idx> UnwindSafe for Clamp<Idx>
where
Idx: UnwindSafe,
Blanket Implementations
impl<T> Any for Clamp<Idx>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Clamp<Idx>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Clamp<Idx>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> From<T> for Clamp<Idx>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> SizeHint for Clamp<Idx>
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for Clamp<Idx>
impl<T, U> Into<U> for Clamp<Idx>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Clamp<Idx>
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Clamp<Idx>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>