Created
November 19, 2020 07:56
-
-
Save tpmccallum/b67977434a88ceb3c8c62ed4c72467f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pub fn search_bytes_single_input(byte_array: &[u8]) -> String { | |
| let mut number_of_bytes_str = "".to_string(); | |
| for i in 0..10 { | |
| number_of_bytes_str.push_str(&byte_array[i].to_string()); | |
| } | |
| let number_of_bytes_usize: usize = number_of_bytes_str.parse().unwrap(); | |
| let needle: &[u8] = &byte_array.get(10..10 + number_of_bytes_usize).unwrap(); | |
| let haystack: &[u8] = &byte_array.get(10 + number_of_bytes_usize..).unwrap(); | |
| match haystack.windows(needle.len()).position(|window| window == needle){ | |
| Some(_) => "Present".to_string(), | |
| None => "Absent".to_string() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment