Javascript provides
"abcde".indexOf("de") === 3
.
I'd like to do the same thing for a &[T]
where T implements PartialEq.
fn search_haystack<T: PartialEq>(needle: &[T], haystack: &[T]) -> Option<usize> {
todo!()
}
fn main() {
let haystack = [1,2,3,4,5];
let needle = [3,4];
assert_eq!(search_haystack(&needle, &haystack), Some(2))
}
I could write this function myself but it seems like something the stdlib would offer, and I have not been able to find it. How do I accomplish this efficiently using the stdlib (not nightly).