Trait SliceExt

Source
pub trait SliceExt<T> {
    // Required methods
    fn trim_start_matches<F>(&self, f: F) -> &[T]
       where F: FnMut(&T) -> bool;
    fn trim_end_matches<F>(&self, f: F) -> &[T]
       where F: FnMut(&T) -> bool;
    fn group_by_key<K, F>(&self, f: F) -> GroupByKey<'_, T, F> 
       where F: FnMut(&T) -> K,
             K: PartialEq;
    fn split_prefix_suffix<F>(&self, f: F) -> (usize, usize)
       where F: FnMut(&T) -> bool;
}
Expand description

Extra methods for [T].

Required Methods§

Source

fn trim_start_matches<F>(&self, f: F) -> &[T]
where F: FnMut(&T) -> bool,

Returns a slice with all matching elements from the start of the slice removed.

Source

fn trim_end_matches<F>(&self, f: F) -> &[T]
where F: FnMut(&T) -> bool,

Returns a slice with all matching elements from the end of the slice removed.

Source

fn group_by_key<K, F>(&self, f: F) -> GroupByKey<'_, T, F>
where F: FnMut(&T) -> K, K: PartialEq,

Split a slice into consecutive runs with the same key and yield for each such run the key and the slice of elements with that key.

Source

fn split_prefix_suffix<F>(&self, f: F) -> (usize, usize)
where F: FnMut(&T) -> bool,

Computes two indices which split a slice into three parts.

  • A prefix which matches f
  • An inner portion
  • A suffix which matches f and does not overlap with the prefix

If all elements match f, the prefix becomes self and the suffix will be empty.

Returns the indices at which the inner portion and the suffix start.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> SliceExt<T> for [T]

Source§

fn trim_start_matches<F>(&self, f: F) -> &[T]
where F: FnMut(&T) -> bool,

Source§

fn trim_end_matches<F>(&self, f: F) -> &[T]
where F: FnMut(&T) -> bool,

Source§

fn group_by_key<K, F>(&self, f: F) -> GroupByKey<'_, T, F>

Source§

fn split_prefix_suffix<F>(&self, f: F) -> (usize, usize)
where F: FnMut(&T) -> bool,

Implementors§