pub struct Slice<T>(/* private fields */);
Expand description
Implementations§
Source§impl<T> Slice<T>
§core::slice
namespaced methods
impl<T> Slice<T>
§core::slice
namespaced methods
Sourcepub const fn from_ref(s: &T) -> &[T] ⓘ
pub const fn from_ref(s: &T) -> &[T] ⓘ
Converts a reference to T
into a slice of length 1 (without copying).
See core::slice::
from_ref
.
Sourcepub const fn from_mut(s: &mut T) -> &mut [T] ⓘ
pub const fn from_mut(s: &mut T) -> &mut [T] ⓘ
Converts a reference to T
into a slice of length 1 (without copying).
See core::slice::
from_mut
.
Sourcepub const unsafe fn from_raw_parts<'a>(data: *const T, len: usize) -> &'a [T] ⓘ
Available on crate feature unsafe_slice
only.
pub const unsafe fn from_raw_parts<'a>(data: *const T, len: usize) -> &'a [T] ⓘ
unsafe_slice
only.Forms a shared slice from a pointer and a length.
§Safety
See core::slice::
from_raw_parts
See also Ptr::
slice_from_raw_parts
.
Sourcepub const unsafe fn from_raw_parts_mut<'a>(
data: *mut T,
len: usize,
) -> &'a mut [T] ⓘ
Available on crate feature unsafe_slice
only.
pub const unsafe fn from_raw_parts_mut<'a>( data: *mut T, len: usize, ) -> &'a mut [T] ⓘ
unsafe_slice
only.Forms an exclusive slice from a pointer and a length.
§Safety
See core::slice::
from_raw_parts_mut
.
See also Ptr::
slice_from_raw_parts_mut
.
Source§impl<T> Slice<T>
§Methods for shared subslicing using index-based splitting.
impl<T> Slice<T>
§Methods for shared subslicing using index-based splitting.
Sourcepub const fn range_to(slice: &[T], end: usize) -> &[T] ⓘ
pub const fn range_to(slice: &[T], end: usize) -> &[T] ⓘ
Returns a subslice up to the given end
index.
Equivalent to &slice[..end]
.
§Panics
Panics if end
> slice.len()
.
Sourcepub const fn range_from(slice: &[T], start: usize) -> &[T] ⓘ
pub const fn range_from(slice: &[T], start: usize) -> &[T] ⓘ
Returns a subslice starting from the given start
index.
Equivalent to &slice[start..]
.
§Panics
Panics if start
> slice.len()
.
Sourcepub const fn range(slice: &[T], start: usize, end: usize) -> &[T] ⓘ
pub const fn range(slice: &[T], start: usize, end: usize) -> &[T] ⓘ
Returns a subslice from start
(inclusive) to end
(exclusive).
Equivalent to &slice[start..end]
.
§Panics
Panics if start
> len or end
> slice.len()
.
Sourcepub const fn take_first(slice: &[T], n: usize) -> &[T] ⓘ
pub const fn take_first(slice: &[T], n: usize) -> &[T] ⓘ
Returns the first n
elements of the slice.
Equivalent to &slice[..n]
.
§Panics
Panics if n
> slice.len()
.
Sourcepub const fn take_last(slice: &[T], n: usize) -> &[T] ⓘ
pub const fn take_last(slice: &[T], n: usize) -> &[T] ⓘ
Returns the last n
elements of the slice.
Equivalent to &slice[slice.len() - n..]
.
§Panics
Panics if n
> slice.len()
.
Sourcepub const fn take_omit_last(slice: &[T], n: usize) -> &[T] ⓘ
pub const fn take_omit_last(slice: &[T], n: usize) -> &[T] ⓘ
Returns the slice omitting the last n
elements.
Equivalent to &slice[..slice.len() - n]
.
§Panics
Panics if n
> slice.len()
.
Sourcepub const fn range_to_checked(slice: &[T], end: usize) -> Option<&[T]> ⓘ
pub const fn range_to_checked(slice: &[T], end: usize) -> Option<&[T]> ⓘ
Returns a subslice up to the given end
index.
Equivalent to &slice[..end]
.
Returns None
if end
> slice.len()
.
Sourcepub const fn range_from_checked(slice: &[T], start: usize) -> Option<&[T]> ⓘ
pub const fn range_from_checked(slice: &[T], start: usize) -> Option<&[T]> ⓘ
Returns a subslice starting from the given start
index.
Equivalent to &slice[start..]
.
Returns None
if start
> slice.len()
.
Sourcepub const fn range_checked(
slice: &[T],
start: usize,
end: usize,
) -> Option<&[T]> ⓘ
pub const fn range_checked( slice: &[T], start: usize, end: usize, ) -> Option<&[T]> ⓘ
Returns a subslice from start
(inclusive) to end
(exclusive).
Equivalent to &slice[start..end]
.
Returns None
if start
> slice.len()
or end
> slice.len()
.
§Features
This method makes use of of the unsafe_slice
feature is enabled.
Sourcepub const fn take_first_checked(slice: &[T], n: usize) -> Option<&[T]> ⓘ
pub const fn take_first_checked(slice: &[T], n: usize) -> Option<&[T]> ⓘ
Returns the first n
elements of the slice.
Equivalent to &slice[..n]
.
Returns None
if n
> slice.len()
.
Source§impl<T> Slice<T>
§Methods for exclusive subslicing using index-based splitting.
impl<T> Slice<T>
§Methods for exclusive subslicing using index-based splitting.
Sourcepub const fn range_to_mut(slice: &mut [T], end: usize) -> &mut [T] ⓘ
pub const fn range_to_mut(slice: &mut [T], end: usize) -> &mut [T] ⓘ
Returns an exclusive subslice up to the given end
index.
Equivalent to &mut slice[..end]
.
§Panics
Panics if end
> slice.len()
.
Sourcepub const fn range_from_mut(slice: &mut [T], start: usize) -> &mut [T] ⓘ
pub const fn range_from_mut(slice: &mut [T], start: usize) -> &mut [T] ⓘ
Returns an exclusive subslice starting from the given start
index.
Equivalent to &mut slice[start..]
.
§Panics
Panics if start
> slice.len()
.
Sourcepub const fn range_mut(slice: &mut [T], start: usize, end: usize) -> &mut [T] ⓘ
pub const fn range_mut(slice: &mut [T], start: usize, end: usize) -> &mut [T] ⓘ
Returns an exclusive subslice from start
(inclusive) to end
(exclusive).
Equivalent to &mut slice[start..end]
.
§Panics
Panics if start
> slice.len()
or end
> slice.len()
.
Sourcepub const fn take_first_mut(slice: &mut [T], n: usize) -> &mut [T] ⓘ
pub const fn take_first_mut(slice: &mut [T], n: usize) -> &mut [T] ⓘ
Returns the first n
elements of the exclusive slice.
Equivalent to &mut slice[..n]
.
§Panics
Panics if n
> slice.len()
.
Sourcepub const fn take_last_mut(slice: &mut [T], n: usize) -> &mut [T] ⓘ
pub const fn take_last_mut(slice: &mut [T], n: usize) -> &mut [T] ⓘ
Returns the last n
elements of the exclusive slice.
Equivalent to &mut slice[slice.len() - n..]
.
§Panics
Panics if n
> slice.len()
.
Sourcepub const fn take_omit_last_mut(slice: &mut [T], n: usize) -> &mut [T] ⓘ
pub const fn take_omit_last_mut(slice: &mut [T], n: usize) -> &mut [T] ⓘ
Returns the exclusive slice omitting the last n
elements.
Equivalent to &mut slice[..slice.len() - n]
.
§Panics
Panics if n
> slice.len()
.
Sourcepub const fn range_to_mut_checked(
slice: &mut [T],
end: usize,
) -> Option<&mut [T]> ⓘ
pub const fn range_to_mut_checked( slice: &mut [T], end: usize, ) -> Option<&mut [T]> ⓘ
Returns a subslice up to the given end
index.
Equivalent to &mut slice[..end]
.
Returns None
if end
> slice.len()
.
Sourcepub const fn range_from_mut_checked(
slice: &mut [T],
start: usize,
) -> Option<&mut [T]> ⓘ
pub const fn range_from_mut_checked( slice: &mut [T], start: usize, ) -> Option<&mut [T]> ⓘ
Returns a subslice starting from the given start
index.
Equivalent to &mut slice[start..]
.
Returns None
if start
> slice.len()
.
Sourcepub const fn range_mut_checked(
slice: &mut [T],
start: usize,
end: usize,
) -> Option<&mut [T]> ⓘ
pub const fn range_mut_checked( slice: &mut [T], start: usize, end: usize, ) -> Option<&mut [T]> ⓘ
Returns a subslice from start
(inclusive) to end
(exclusive).
Equivalent to &mut slice[start..end]
.
Returns None
if start
> slice.len()
or end
> slice.len()
.
§Features
This method makes use of of the unsafe_slice
feature is enabled.
Sourcepub const fn take_first_mut_checked(
slice: &mut [T],
n: usize,
) -> Option<&mut [T]> ⓘ
pub const fn take_first_mut_checked( slice: &mut [T], n: usize, ) -> Option<&mut [T]> ⓘ
Returns the first n
elements of the slice.
Equivalent to &mut slice[..n]
.
Returns None
if n
> slice.len()
.
Source§impl<T> Slice<T>
§Methods for splitting.
impl<T> Slice<T>
§Methods for splitting.
Sourcepub const fn lsplit(slice: &[T], len: usize) -> &[T] ⓘ
pub const fn lsplit(slice: &[T], len: usize) -> &[T] ⓘ
Returns the leftmost sub-slice
with the given maximum len
.
If len > self.len()
it returns the full slice.
§Example
let v = [1, 2, 3, 4, 5, 6];
assert_eq!(Slice::lsplit(&v, 3), &[1, 2, 3]);
assert_eq!(Slice::lsplit(&v, 0), &[] as &[i32]);
assert_eq!(Slice::lsplit(&v, 10), &[1, 2, 3, 4, 5, 6]);
Sourcepub const fn lsplit_mut(slice: &mut [T], len: usize) -> &mut [T] ⓘ
pub const fn lsplit_mut(slice: &mut [T], len: usize) -> &mut [T] ⓘ
Returns the leftmost exclusive sub-slice
with the given maximum len
.
If left_len > slice.len()
it returns the full slice.
§Example
let mut v = [1, 2, 3, 4, 5, 6];
assert_eq!(Slice::lsplit_mut(&mut v, 3), &mut [1, 2, 3]);
assert_eq!(Slice::lsplit_mut(&mut v, 0), &mut [] as &mut [i32]);
assert_eq!(Slice::lsplit_mut(&mut v, 10), &mut [1, 2, 3, 4, 5, 6]);
See also Slice::lsplit_mut
.
Sourcepub const fn rsplit(slice: &[T], len: usize) -> &[T] ⓘ
pub const fn rsplit(slice: &[T], len: usize) -> &[T] ⓘ
Returns the rightmost sub-slice
with the given maximum len
.
If left_len > slice.len()
it returns the full slice.
§Example
let v = [1, 2, 3, 4, 5, 6];
assert_eq!(Slice::rsplit(&v, 3), &[4, 5, 6]);
assert_eq!(Slice::rsplit(&v, 0), &[] as &[i32]);
assert_eq!(Slice::rsplit(&v, 10), &[1, 2, 3, 4, 5, 6]);
Sourcepub const fn rsplit_mut(slice: &mut [T], len: usize) -> &mut [T] ⓘ
pub const fn rsplit_mut(slice: &mut [T], len: usize) -> &mut [T] ⓘ
Returns the rightmost mutable sub-slice
with the given maximum len
.
If left_len > slice.len()
it returns the full slice.
§Example
let mut v = [1, 2, 3, 4, 5, 6];
assert_eq!(Slice::rsplit_mut(&mut v, 3), &mut [4, 5, 6]);
assert_eq!(Slice::rsplit_mut(&mut v, 0), &mut [] as &mut [i32]);
assert_eq!(Slice::rsplit_mut(&mut v, 10), &mut [1, 2, 3, 4, 5, 6]);
See also Slice::lsplit_mut
.
Sourcepub const fn msplit_left(slice: &[T], len: usize) -> &[T] ⓘ
pub const fn msplit_left(slice: &[T], len: usize) -> &[T] ⓘ
Returns the middle sub-slice
with the given maximum len
and a left bias.
In case of a non-perfect middle split, it will have one character more on the left.
If len > slice.len()
returns the full slice
.
§Example
let v = [1, 2, 3, 4, 5, 6];
assert_eq!(Slice::msplit_left(&v, 0), &[] as &[i32]);
assert_eq!(Slice::msplit_left(&v, 1), &[3]);
assert_eq!(Slice::msplit_left(&v, 2), &[3, 4]);
assert_eq!(Slice::msplit_left(&v, 3), &[2, 3, 4]);
assert_eq!(Slice::msplit_left(&v, 4), &[2, 3, 4, 5]);
assert_eq!(Slice::msplit_left(&v, 5), &[1, 2, 3, 4, 5]);
assert_eq!(Slice::msplit_left(&v, 10), &[1, 2, 3, 4, 5, 6]);
See also Slice::msplit_right
.
Sourcepub const fn msplit_left_mut(slice: &mut [T], len: usize) -> &mut [T] ⓘ
pub const fn msplit_left_mut(slice: &mut [T], len: usize) -> &mut [T] ⓘ
Returns the middle exclusive sub-slice
with the given maximum len
and a
left bias.
In case of a non-perfect middle split, it will have one character more on the left.
If len > slice.len()
returns the full slice
.
§Example
let mut v = [1, 2, 3, 4, 5, 6];
assert_eq!(Slice::msplit_left_mut(&mut v, 0), &mut [] as &mut [i32]);
assert_eq!(Slice::msplit_left_mut(&mut v, 1), &mut [3]);
assert_eq!(Slice::msplit_left_mut(&mut v, 2), &mut [3, 4]);
assert_eq!(Slice::msplit_left_mut(&mut v, 3), &mut [2, 3, 4]);
assert_eq!(Slice::msplit_left_mut(&mut v, 4), &mut [2, 3, 4, 5]);
assert_eq!(Slice::msplit_left_mut(&mut v, 5), &mut [1, 2, 3, 4, 5]);
assert_eq!(Slice::msplit_left_mut(&mut v, 10), &mut [1, 2, 3, 4, 5, 6]);
See also Slice::msplit_right_mut
.
Sourcepub const fn msplit_right(slice: &[T], len: usize) -> &[T] ⓘ
pub const fn msplit_right(slice: &[T], len: usize) -> &[T] ⓘ
Returns the middle sub-slice
with the given maximum len
and a right bias.
In case of a non-perfect middle split, it will have one character more on the right.
If len > slice.len()
returns the full slice
.
§Example
let v = [1, 2, 3, 4, 5, 6];
assert_eq!(Slice::msplit_right(&v, 0), &[] as &[i32]);
assert_eq!(Slice::msplit_right(&v, 1), &[4]);
assert_eq!(Slice::msplit_right(&v, 2), &[3, 4]);
assert_eq!(Slice::msplit_right(&v, 3), &[3, 4, 5]);
assert_eq!(Slice::msplit_right(&v, 4), &[2, 3, 4, 5]);
assert_eq!(Slice::msplit_right(&v, 5), &[2, 3, 4, 5, 6]);
assert_eq!(Slice::msplit_right(&v, 10), &[1, 2, 3, 4, 5, 6]);
See also Slice::msplit_left
.
Sourcepub const fn msplit_right_mut(slice: &mut [T], len: usize) -> &mut [T] ⓘ
pub const fn msplit_right_mut(slice: &mut [T], len: usize) -> &mut [T] ⓘ
Returns the middle exclusive sub-slice
with the given maximum len
and a
right bias.
In case of a non-perfect middle split, it will have one character more on the right.
If len > slice.len()
returns the full slice
.
§Example
let mut v = [1, 2, 3, 4, 5, 6];
assert_eq!(Slice::msplit_right_mut(&mut v, 0), &mut [] as &mut[i32]);
assert_eq!(Slice::msplit_right_mut(&mut v, 1), &mut [4]);
assert_eq!(Slice::msplit_right_mut(&mut v, 2), &mut [3, 4]);
assert_eq!(Slice::msplit_right_mut(&mut v, 3), &mut [3, 4, 5]);
assert_eq!(Slice::msplit_right_mut(&mut v, 4), &mut [2, 3, 4, 5]);
assert_eq!(Slice::msplit_right_mut(&mut v, 5), &mut [2, 3, 4, 5, 6]);
assert_eq!(Slice::msplit_right_mut(&mut v, 10), &mut [1, 2, 3, 4, 5, 6]);
See also Slice::msplit_left_mut
.
Auto Trait Implementations§
impl<T> Freeze for Slice<T>
impl<T> RefUnwindSafe for Slice<T>where
T: RefUnwindSafe,
impl<T> Send for Slice<T>where
T: Send,
impl<T> Sync for Slice<T>where
T: Sync,
impl<T> Unpin for Slice<T>where
T: Unpin,
impl<T> UnwindSafe for Slice<T>where
T: UnwindSafe,
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
Source§impl<T> ByteSized for T
impl<T> ByteSized for T
Source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Source§fn byte_align(&self) -> usize ⓘ
fn byte_align(&self) -> usize ⓘ
Source§fn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Source§impl<T, R> Chain<R> for Twhere
T: ?Sized,
impl<T, R> Chain<R> for Twhere
T: ?Sized,
Source§impl<T> ExtAny for T
impl<T> ExtAny for T
Source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Source§impl<T> ExtMem for Twhere
T: ?Sized,
impl<T> ExtMem for Twhere
T: ?Sized,
Source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Source§fn mem_align_of_val(&self) -> usize ⓘ
fn mem_align_of_val(&self) -> usize ⓘ
Source§fn mem_size_of_val(&self) -> usize ⓘ
fn mem_size_of_val(&self) -> usize ⓘ
Source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true
if dropping values of this type matters. Read moreSource§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self
without running its destructor. Read moreSource§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Source§unsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice
only.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Hook for T
impl<T> Hook for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError> ⓘ
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError> ⓘ
§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out
indicating that a T
is niched.