# Trait core::slice::SliceExt [−] [src]

    pub trait SliceExt {
        type Item;
        fn split_at(&self, mid: usize) -> (&[Self::Item], &[Self::Item]);
        fn iter(&self) -> Iter<Self::Item>;
        fn split<P>(&self, pred: P) -> Split<Self::Item, P>
        where
            P: FnMut(&Self::Item) -> bool;
        fn rsplit<P>(&self, pred: P) -> RSplit<Self::Item, P>
        where
            P: FnMut(&Self::Item) -> bool;
        fn splitn<P>(&self, n: usize, pred: P) -> SplitN<Self::Item, P>
        where
            P: FnMut(&Self::Item) -> bool;
        fn rsplitn<P>(&self, n: usize, pred: P) -> RSplitN<Self::Item, P>
        where
            P: FnMut(&Self::Item) -> bool;
        fn windows(&self, size: usize) -> Windows<Self::Item>;
        fn chunks(&self, size: usize) -> Chunks<Self::Item>;
        fn exact_chunks(&self, size: usize) -> ExactChunks<Self::Item>;
        fn get<I>(&self, index: I) -> Option<&I::Output>
        where
            I: SliceIndex<Self>;
        fn first(&self) -> Option<&Self::Item>;
        fn split_first(&self) -> Option<(&Self::Item, &[Self::Item])>;
        fn split_last(&self) -> Option<(&Self::Item, &[Self::Item])>;
        fn last(&self) -> Option<&Self::Item>;
        unsafe fn get_unchecked<I>(&self, index: I) -> &I::Output
        where
            I: SliceIndex<Self>;
        fn as_ptr(&self) -> *const Self::Item;
        fn binary_search(&self, x: &Self::Item) -> Result<usize, usize>
        where
            Self::Item: Ord;
        fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
        where
            F: FnMut(&'a Self::Item) -> Ordering;
        fn binary_search_by_key<'a, B, F>(
            &'a self,
            b: &B,
            f: F
        ) -> Result<usize, usize>
        where
            F: FnMut(&'a Self::Item) -> B,
            B: Ord;
        fn len(&self) -> usize;
        fn get_mut<I>(&mut self, index: I) -> Option<&mut I::Output>
        where
            I: SliceIndex<Self>;
        fn iter_mut(&mut self) -> IterMut<Self::Item>;
        fn first_mut(&mut self) -> Option<&mut Self::Item>;
        fn split_first_mut(
            &mut self
        ) -> Option<(&mut Self::Item, &mut [Self::Item])>;
        fn split_last_mut(&mut self) -> Option<(&mut Self::Item, &mut [Self::Item])>;
        fn last_mut(&mut self) -> Option<&mut Self::Item>;
        fn split_mut<P>(&mut self, pred: P) -> SplitMut<Self::Item, P>
        where
            P: FnMut(&Self::Item) -> bool;
        fn rsplit_mut<P>(&mut self, pred: P) -> RSplitMut<Self::Item, P>
        where
            P: FnMut(&Self::Item) -> bool;
        fn splitn_mut<P>(&mut self, n: usize, pred: P) -> SplitNMut<Self::Item, P>
        where
            P: FnMut(&Self::Item) -> bool;
        fn rsplitn_mut<P>(&mut self, n: usize, pred: P) -> RSplitNMut<Self::Item, P>
        where
            P: FnMut(&Self::Item) -> bool;
        fn chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<Self::Item>;
        fn exact_chunks_mut(&mut self, size: usize) -> ExactChunksMut<Self::Item>;
        fn swap(&mut self, a: usize, b: usize);
        fn split_at_mut(
            &mut self,
            mid: usize
        ) -> (&mut [Self::Item], &mut [Self::Item]);
        fn reverse(&mut self);
        unsafe fn get_unchecked_mut<I>(&mut self, index: I) -> &mut I::Output
        where
            I: SliceIndex<Self>;
        fn as_mut_ptr(&mut self) -> *mut Self::Item;
        fn contains(&self, x: &Self::Item) -> bool
        where
            Self::Item: PartialEq;
        fn starts_with(&self, needle: &[Self::Item]) -> bool
        where
            Self::Item: PartialEq;
        fn ends_with(&self, needle: &[Self::Item]) -> bool
        where
            Self::Item: PartialEq;
        fn rotate_left(&mut self, mid: usize);
        fn rotate_right(&mut self, k: usize);
        fn clone_from_slice(&mut self, src: &[Self::Item])
        where
            Self::Item: Clone;
        fn copy_from_slice(&mut self, src: &[Self::Item])
        where
            Self::Item: Copy;
        fn swap_with_slice(&mut self, src: &mut [Self::Item]);
        fn sort_unstable(&mut self)
        where
            Self::Item: Ord;
        fn sort_unstable_by<F>(&mut self, compare: F)
        where
            F: FnMut(&Self::Item, &Self::Item) -> Ordering;
        fn sort_unstable_by_key<B, F>(&mut self, f: F)
        where
            F: FnMut(&Self::Item) -> B,
            B: Ord;

        fn is_empty(&self) -> bool { ... }
    }

🔬 This is a nightly-only experimental API. (`core_slice_ext` #32110)

stable interface provided by `impl [T]` in later crates

Extension methods for slices.

## Associated Types

### `type Item`

🔬 This is a nightly-only experimental API. (`core_slice_ext` #32110)

stable interface provided by `impl [T]` in later crates

## Required Methods

### `fn split_at(&self, mid: usize) -> (&[Self::Item], &[Self::Item])`
1.6.0

ⓘImportant traits for Iter<'a, T>

### Important traits for Iter<'a, T>

`impl<'a, T> Iterator for Iter<'a, T> type Item = &'a T;`

### `fn iter(&self) -> Iter<Self::Item>`
1.6.0

ⓘImportant traits for Split<'a, T, P>

### Important traits for Split<'a, T, P>

`impl<'a, T, P> Iterator for Split<'a, T, P> where
P: FnMut(&T) -> bool, type Item = &'a [T];`

### `fn split<P>(&self, pred: P) -> Split<Self::Item, P> where
P: FnMut(&Self::Item) -> bool,`
1.6.0

ⓘImportant traits for RSplit<'a, T, P>

### Important traits for RSplit<'a, T, P>

`impl<'a, T, P> Iterator for RSplit<'a, T, P> where
P: FnMut(&T) -> bool, type Item = &'a [T];`

### `fn rsplit<P>(&self, pred: P) -> RSplit<Self::Item, P> where
P: FnMut(&Self::Item) -> bool,`

🔬 This is a nightly-only experimental API. (`slice_rsplit` #41020)
ⓘImportant traits for SplitN<'a, T, P>

### Important traits for SplitN<'a, T, P>

`impl<'a, T, P> Iterator for SplitN<'a, T, P> where
P: FnMut(&T) -> bool, type Item = &'a [T];`

### `fn splitn<P>(&self, n: usize, pred: P) -> SplitN<Self::Item, P> where
P: FnMut(&Self::Item) -> bool,`
1.6.0

ⓘImportant traits for RSplitN<'a, T, P>

### Important traits for RSplitN<'a, T, P>

`impl<'a, T, P> Iterator for RSplitN<'a, T, P> where
P: FnMut(&T) -> bool, type Item = &'a [T];`

### `fn rsplitn<P>(&self, n: usize, pred: P) -> RSplitN<Self::Item, P> where
P: FnMut(&Self::Item) -> bool,`
1.6.0

ⓘImportant traits for Windows<'a, T>

### Important traits for Windows<'a, T>

`impl<'a, T> Iterator for Windows<'a, T> type Item = &'a [T];`

### `fn windows(&self, size: usize) -> Windows<Self::Item>`
1.6.0

ⓘImportant traits for Chunks<'a, T>

### Important traits for Chunks<'a, T>

`impl<'a, T> Iterator for Chunks<'a, T> type Item = &'a [T];`

### `fn chunks(&self, size: usize) -> Chunks<Self::Item>`
1.6.0

ⓘImportant traits for ExactChunks<'a, T>

### Important traits for ExactChunks<'a, T>

`impl<'a, T> Iterator for ExactChunks<'a, T> type Item = &'a [T];`

### `fn exact_chunks(&self, size: usize) -> ExactChunks<Self::Item>`

🔬 This is a nightly-only experimental API. (`exact_chunks` #47115)

### `fn get<I>(&self, index: I) -> Option<&I::Output> where
I: SliceIndex<Self>,`
1.6.0

### `fn first(&self) -> Option<&Self::Item>`
1.6.0

### `fn split_first(&self) -> Option<(&Self::Item, &[Self::Item])>`
1.6.0

### `fn split_last(&self) -> Option<(&Self::Item, &[Self::Item])>`
1.6.0

### `fn last(&self) -> Option<&Self::Item>`
1.6.0

### `unsafe fn get_unchecked<I>(&self, index: I) -> &I::Output where
I: SliceIndex<Self>,`
1.6.0

### `fn as_ptr(&self) -> *const Self::Item`
1.6.0

### `fn binary_search(&self, x: &Self::Item) -> Result<usize, usize> where
Self::Item: Ord,`
1.6.0

### `fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize> where
F: FnMut(&'a Self::Item) -> Ordering,`
1.6.0

### `fn binary_search_by_key<'a, B, F>(&'a self, b: &B, f: F) -> Result<usize, usize> where
F: FnMut(&'a Self::Item) -> B,
B: Ord,`
1.10.0

### `fn len(&self) -> usize`
1.6.0

### `fn get_mut<I>(&mut self, index: I) -> Option<&mut I::Output> where
I: SliceIndex<Self>,`
1.6.0

ⓘImportant traits for IterMut<'a, T>

### Important traits for IterMut<'a, T>

`impl<'a, T> Iterator for IterMut<'a, T> type Item = &'a mut T;`

### `fn iter_mut(&mut self) -> IterMut<Self::Item>`
1.6.0

### `fn first_mut(&mut self) -> Option<&mut Self::Item>`
1.6.0

### `fn split_first_mut(&mut self) -> Option<(&mut Self::Item, &mut [Self::Item])>`
1.6.0

### `fn split_last_mut(&mut self) -> Option<(&mut Self::Item, &mut [Self::Item])>`
1.6.0

### `fn last_mut(&mut self) -> Option<&mut Self::Item>`
1.6.0

ⓘImportant traits for SplitMut<'a, T, P>

### Important traits for SplitMut<'a, T, P>

`impl<'a, T, P> Iterator for SplitMut<'a, T, P> where
P: FnMut(&T) -> bool, type Item = &'a mut [T];`

### `fn split_mut<P>(&mut self, pred: P) -> SplitMut<Self::Item, P> where
P: FnMut(&Self::Item) -> bool,`
1.6.0

ⓘImportant traits for RSplitMut<'a, T, P>

### Important traits for RSplitMut<'a, T, P>

`impl<'a, T, P> Iterator for RSplitMut<'a, T, P> where
P: FnMut(&T) -> bool, type Item = &'a mut [T];`

### `fn rsplit_mut<P>(&mut self, pred: P) -> RSplitMut<Self::Item, P> where
P: FnMut(&Self::Item) -> bool,`

🔬 This is a nightly-only experimental API. (`slice_rsplit` #41020)
ⓘImportant traits for SplitNMut<'a, T, P>

### Important traits for SplitNMut<'a, T, P>

`impl<'a, T, P> Iterator for SplitNMut<'a, T, P> where
P: FnMut(&T) -> bool, type Item = &'a mut [T];`

### `fn splitn_mut<P>(&mut self, n: usize, pred: P) -> SplitNMut<Self::Item, P> where
P: FnMut(&Self::Item) -> bool,`
1.6.0

ⓘImportant traits for RSplitNMut<'a, T, P>

### Important traits for RSplitNMut<'a, T, P>

`impl<'a, T, P> Iterator for RSplitNMut<'a, T, P> where
P: FnMut(&T) -> bool, type Item = &'a mut [T];`

### `fn rsplitn_mut<P>(&mut self, n: usize, pred: P) -> RSplitNMut<Self::Item, P> where
P: FnMut(&Self::Item) -> bool,`
1.6.0

ⓘImportant traits for ChunksMut<'a, T>

### Important traits for ChunksMut<'a, T>

`impl<'a, T> Iterator for ChunksMut<'a, T> type Item = &'a mut [T];`

### `fn chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<Self::Item>`
1.6.0

ⓘImportant traits for ExactChunksMut<'a, T>

### Important traits for ExactChunksMut<'a, T>

`impl<'a, T> Iterator for ExactChunksMut<'a, T> type Item = &'a mut [T];`

### `fn exact_chunks_mut(&mut self, size: usize) -> ExactChunksMut<Self::Item>`

🔬 This is a nightly-only experimental API. (`exact_chunks` #47115)

### `fn swap(&mut self, a: usize, b: usize)`
1.6.0

### `fn split_at_mut(&mut self, mid: usize) -> (&mut [Self::Item], &mut [Self::Item])`
1.6.0

### `fn reverse(&mut self)`
1.6.0

### `unsafe fn get_unchecked_mut<I>(&mut self, index: I) -> &mut I::Output where
I: SliceIndex<Self>,`
1.6.0

### `fn as_mut_ptr(&mut self) -> *mut Self::Item`
1.6.0

### `fn contains(&self, x: &Self::Item) -> bool where
Self::Item: PartialEq,`
1.6.0

### `fn starts_with(&self, needle: &[Self::Item]) -> bool where
Self::Item: PartialEq,`
1.6.0

### `fn ends_with(&self, needle: &[Self::Item]) -> bool where
Self::Item: PartialEq,`
1.6.0

### `fn rotate_left(&mut self, mid: usize)`

🔬 This is a nightly-only experimental API. (`slice_rotate` #41891)

### `fn rotate_right(&mut self, k: usize)`

🔬 This is a nightly-only experimental API. (`slice_rotate` #41891)

### `fn clone_from_slice(&mut self, src: &[Self::Item]) where
Self::Item: Clone,`
1.7.0

### `fn copy_from_slice(&mut self, src: &[Self::Item]) where
Self::Item: Copy,`
1.9.0

### `fn swap_with_slice(&mut self, src: &mut [Self::Item])`

🔬 This is a nightly-only experimental API. (`swap_with_slice` #44030)

### `fn sort_unstable(&mut self) where
Self::Item: Ord,`
1.20.0

### `fn sort_unstable_by<F>(&mut self, compare: F) where
F: FnMut(&Self::Item, &Self::Item) -> Ordering,`
1.20.0

### `fn sort_unstable_by_key<B, F>(&mut self, f: F) where
F: FnMut(&Self::Item) -> B,
B: Ord,`
1.20.0

## Provided Methods

### `fn is_empty(&self) -> bool`
1.6.0

## Implementors

- [src]
  `impl<T> SliceExt for [T] type Item = T;`

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)