Skip to content

Instantly share code, notes, and snippets.

@graue
Created April 1, 2013 06:53
Show Gist options
  • Save graue/5283546 to your computer and use it in GitHub Desktop.
Save graue/5283546 to your computer and use it in GitHub Desktop.
Attempt to update code for Rust 0.6
extern mod std;
use core::num::IntConvertible;
use core::ops::Modulo;
fn find_even<T:Copy+Modulo<T,T>+IntConvertible+cmp::Eq>(vec: &[T]) -> Option<T> {
let zero: T = IntConvertible::from_int(0);
let two: T = IntConvertible::from_int(2);
for vec.each |x| {
if *x % two == zero {
return Some(*x);
}
}
None
}
fn main() {
io::println(match find_even(@[1,2,3,5,7,9,10]) {
Some(x) => int::to_str(x),
None => ~"No even numbers"
});
}
// Output:
// find_even_generic.rs:17:22: 17:31 error: failed to find an implementation of trait core::num::IntConvertible for <V2>
// find_even_generic.rs:17 io::println(match find_even(@[1,2,3,5,7,9,10]) {
// ^~~~~~~~~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment