Created
October 3, 2014 07:44
-
-
Save little-arhat/c81c7d45901367495694 to your computer and use it in GitHub Desktop.
This file contains 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
// find_str uses Searcher which uses &[u8] internally | |
fn find_bytes(haystack: &[u8], needle: &[u8]) -> Option<uint> { | |
unsafe { | |
let hs:&str = std::mem::transmute(haystack); | |
let ns:&str = std::mem::transmute(needle); | |
hs.find_str(ns) | |
} | |
} | |
fn main() { | |
let h = [1u8, 2, 3, 4, 5, 6, 7]; | |
let n = [5u8, 6]; | |
let p = find_bytes(h, n); | |
println!("Found on {}", p.unwrap()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment