Skip to content

Instantly share code, notes, and snippets.

@little-arhat
Created October 3, 2014 07:44
Show Gist options
  • Save little-arhat/c81c7d45901367495694 to your computer and use it in GitHub Desktop.
Save little-arhat/c81c7d45901367495694 to your computer and use it in GitHub Desktop.
// 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