Show More
@@ -10,6 +10,26 b'' | |||
|
10 | 10 | pub mod files; |
|
11 | 11 | pub mod hg_path; |
|
12 | 12 | |
|
13 | /// Useful until rust/issues/56345 is stable | |
|
14 | /// | |
|
15 | /// # Examples | |
|
16 | /// | |
|
17 | /// ``` | |
|
18 | /// use crate::hg::utils::find_slice_in_slice; | |
|
19 | /// | |
|
20 | /// let haystack = b"This is the haystack".to_vec(); | |
|
21 | /// assert_eq!(find_slice_in_slice(&haystack, b"the"), Some(8)); | |
|
22 | /// assert_eq!(find_slice_in_slice(&haystack, b"not here"), None); | |
|
23 | /// ``` | |
|
24 | pub fn find_slice_in_slice<T>(slice: &[T], needle: &[T]) -> Option<usize> | |
|
25 | where | |
|
26 | for<'a> &'a [T]: PartialEq, | |
|
27 | { | |
|
28 | slice | |
|
29 | .windows(needle.len()) | |
|
30 | .position(|window| window == needle) | |
|
31 | } | |
|
32 | ||
|
13 | 33 | /// Replaces the `from` slice with the `to` slice inside the `buf` slice. |
|
14 | 34 | /// |
|
15 | 35 | /// # Examples |
General Comments 0
You need to be logged in to leave comments.
Login now