Skip to content

Instantly share code, notes, and snippets.

Created July 24, 2015 13:03
Show Gist options
  • Save anonymous/20e9129c61599641d7bf to your computer and use it in GitHub Desktop.
Save anonymous/20e9129c61599641d7bf to your computer and use it in GitHub Desktop.
Shared via Rust Playground
fn filter<T>(res: &mut [usize], lhs: &[T], rhs: &[T])
where T : Copy + PartialOrd {
let mut matched: usize = 0;
for x in 0..lhs.len() {
res[matched] = x;
matched = matched + if lhs[x] > rhs[x] { 1 } else { 0 };
}
}
fn main() {
let mut res: [usize;4] = [0,0,0,0];
let lhs: [i32;4] = [1,2,3,4];
let rhs: [i32;4] = [5,6,7,8];
filter(&mut res, &lhs, &rhs);
for x in 0..res.len() {
println!("{}", res[x]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment