pub struct Slice<'a, S: ?Sized, Index>(pub &'a S, pub Index);Expand description
A pending slice operation. This can be used to slice &[T] and &str in a const context
with any valid slice index.
You can use the slice!, try_slice!, split_slice_at! and try_split_slice_at!
convenience macros instead of using this directly.
const STR: &str = Slice("const slice", ..5).index(); // "const"
const BYTES: &[u8] = Slice(b"01234", 1..=3).index(); // b"123"Tuple Fields§
§0: &'a S§1: IndexImplementations§
source§impl<'a, T> Slice<'a, [T], RangeInclusive<usize>>
impl<'a, T> Slice<'a, [T], RangeInclusive<usize>>
sourcepub const fn get(
&self,
) -> Option<&'a <RangeInclusive<usize> as SliceIndex<[T]>>::Output>
pub const fn get( &self, ) -> Option<&'a <RangeInclusive<usize> as SliceIndex<[T]>>::Output>
Evaluate this slice operation, or return None on error
sourcepub const fn index(
&self,
) -> &'a <RangeInclusive<usize> as SliceIndex<[T]>>::Output
pub const fn index( &self, ) -> &'a <RangeInclusive<usize> as SliceIndex<[T]>>::Output
Evaluate this slice operation, or panic on error
source§impl<'a, T, const N: usize> Slice<'a, [T; N], RangeInclusive<usize>>
impl<'a, T, const N: usize> Slice<'a, [T; N], RangeInclusive<usize>>
sourcepub const fn get(
&self,
) -> Option<&'a <RangeInclusive<usize> as SliceIndex<[T; N]>>::Output>
pub const fn get( &self, ) -> Option<&'a <RangeInclusive<usize> as SliceIndex<[T; N]>>::Output>
Evaluate this slice operation, or return None on error
sourcepub const fn index(
&self,
) -> &'a <RangeInclusive<usize> as SliceIndex<[T; N]>>::Output
pub const fn index( &self, ) -> &'a <RangeInclusive<usize> as SliceIndex<[T; N]>>::Output
Evaluate this slice operation, or panic on error
source§impl<'a> Slice<'a, str, RangeInclusive<usize>>
impl<'a> Slice<'a, str, RangeInclusive<usize>>
sourcepub const fn get(
&self,
) -> Option<&'a <RangeInclusive<usize> as SliceIndex<str>>::Output>
pub const fn get( &self, ) -> Option<&'a <RangeInclusive<usize> as SliceIndex<str>>::Output>
Evaluate this slice operation, or return None on error
sourcepub const fn index(
&self,
) -> &'a <RangeInclusive<usize> as SliceIndex<str>>::Output
pub const fn index( &self, ) -> &'a <RangeInclusive<usize> as SliceIndex<str>>::Output
Evaluate this slice operation, or panic on error
source§impl<'a, T> Slice<'a, [T], RangeToInclusive<usize>>
impl<'a, T> Slice<'a, [T], RangeToInclusive<usize>>
sourcepub const fn get(
&self,
) -> Option<&'a <RangeToInclusive<usize> as SliceIndex<[T]>>::Output>
pub const fn get( &self, ) -> Option<&'a <RangeToInclusive<usize> as SliceIndex<[T]>>::Output>
Evaluate this slice operation, or return None on error
sourcepub const fn index(
&self,
) -> &'a <RangeToInclusive<usize> as SliceIndex<[T]>>::Output
pub const fn index( &self, ) -> &'a <RangeToInclusive<usize> as SliceIndex<[T]>>::Output
Evaluate this slice operation, or panic on error
source§impl<'a, T, const N: usize> Slice<'a, [T; N], RangeToInclusive<usize>>
impl<'a, T, const N: usize> Slice<'a, [T; N], RangeToInclusive<usize>>
sourcepub const fn get(
&self,
) -> Option<&'a <RangeToInclusive<usize> as SliceIndex<[T; N]>>::Output>
pub const fn get( &self, ) -> Option<&'a <RangeToInclusive<usize> as SliceIndex<[T; N]>>::Output>
Evaluate this slice operation, or return None on error
sourcepub const fn index(
&self,
) -> &'a <RangeToInclusive<usize> as SliceIndex<[T; N]>>::Output
pub const fn index( &self, ) -> &'a <RangeToInclusive<usize> as SliceIndex<[T; N]>>::Output
Evaluate this slice operation, or panic on error
source§impl<'a> Slice<'a, str, RangeToInclusive<usize>>
impl<'a> Slice<'a, str, RangeToInclusive<usize>>
sourcepub const fn get(
&self,
) -> Option<&'a <RangeToInclusive<usize> as SliceIndex<str>>::Output>
pub const fn get( &self, ) -> Option<&'a <RangeToInclusive<usize> as SliceIndex<str>>::Output>
Evaluate this slice operation, or return None on error
sourcepub const fn index(
&self,
) -> &'a <RangeToInclusive<usize> as SliceIndex<str>>::Output
pub const fn index( &self, ) -> &'a <RangeToInclusive<usize> as SliceIndex<str>>::Output
Evaluate this slice operation, or panic on error