Hi.
I want to read some bytes from a file and find subslice's first index, like find()
of String
But I can't find find()
for Vec<u8>
but in String
only.
Is there a function for this?
I tried the below but is slower than converting string lossy and using find()
pub fn find_subsequence<T>(haystack: &[T], needle: &[T]) -> Option<usize>
where for<'a> &'a [T]: PartialEq
{
haystack.windows(needle.len()).position(|window| window == needle)
}