pub trait SliceFind<T>: Slice<Item = T> {
// Required methods
const fn find(&self, x: &T) -> Option<usize>
where T: PartialEq;
const fn find_by<'a, F>(&'a self, f: F) -> Option<usize>
where F: FnMut(&'a T) -> bool,
T: 'a;
const fn find_by_key<'a, B, F>(&'a self, b: &B, f: F) -> Option<usize>
where F: FnMut(&'a T) -> B,
B: PartialEq,
T: 'a;
const fn rfind(&self, x: &T) -> Option<usize>
where T: PartialEq;
const fn rfind_by<'a, F>(&'a self, f: F) -> Option<usize>
where F: FnMut(&'a T) -> bool,
T: 'a;
const fn rfind_by_key<'a, B, F>(&'a self, b: &B, f: F) -> Option<usize>
where F: FnMut(&'a T) -> B,
B: PartialEq,
T: 'a;
}Required Methods§
Sourceconst fn find(&self, x: &T) -> Option<usize>where
T: PartialEq,
const fn find(&self, x: &T) -> Option<usize>where
T: PartialEq,
Performs a linear search for the first value that equals x.
§Example
use slice_ops::ops::*;
// v
let x = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3];
let i = x.find(&5).unwrap();
assert_eq!(i, 4);
assert_eq!(x[i], 5);Sourceconst fn find_by<'a, F>(&'a self, f: F) -> Option<usize>
const fn find_by<'a, F>(&'a self, f: F) -> Option<usize>
Performs a linear search for the first value that satisfies the given predicate.
§Example
use slice_ops::ops::*;
// v
let x = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3];
let f = |&xn| xn > 5;
let i = x.find_by(f).unwrap();
assert_eq!(i, 5);Sourceconst fn find_by_key<'a, B, F>(&'a self, b: &B, f: F) -> Option<usize>
const fn find_by_key<'a, B, F>(&'a self, b: &B, f: F) -> Option<usize>
Performs a linear search for the first value that matches the given key given a hashing function.
§Example
use slice_ops::ops::*;
// v
let x = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3];
let f = |&xn| xn % 2;
let i = x.find_by_key(&0, f).unwrap();
assert_eq!(i, 2);Sourceconst fn rfind(&self, x: &T) -> Option<usize>where
T: PartialEq,
const fn rfind(&self, x: &T) -> Option<usize>where
T: PartialEq,
Performs a linear search from the right for the first value that equals x.
§Example
use slice_ops::ops::*;
// v
let x = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3];
let i = x.rfind(&5).unwrap();
assert_eq!(i, 8);
assert_eq!(x[i], 5);Sourceconst fn rfind_by<'a, F>(&'a self, f: F) -> Option<usize>
const fn rfind_by<'a, F>(&'a self, f: F) -> Option<usize>
Performs a linear search from the right for the first value that satisfies the given predicate.
§Example
use slice_ops::ops::*;
// v
let x = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3];
let f = |&xn| xn > 5;
let i = x.rfind_by(f).unwrap();
assert_eq!(i, 7);Sourceconst fn rfind_by_key<'a, B, F>(&'a self, b: &B, f: F) -> Option<usize>
const fn rfind_by_key<'a, B, F>(&'a self, b: &B, f: F) -> Option<usize>
Performs a linear search from the right for the first value that matches the given key given a hashing function.
§Example
use slice_ops::ops::*;
// v
let x = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3];
let f = |&xn| xn % 2;
let i = x.rfind_by_key(&0, f).unwrap();
assert_eq!(i, 7);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.