Skip to content

Instantly share code, notes, and snippets.

@hyunsik
Forked from anonymous/playground.rs
Created July 24, 2015 13:03
Show Gist options
  • Save hyunsik/c873d59a438e3c910c65 to your computer and use it in GitHub Desktop.
Save hyunsik/c873d59a438e3c910c65 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