Skip to content

Instantly share code, notes, and snippets.

@LongHairedHacker
Created November 23, 2016 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LongHairedHacker/b66319e49b4789c2b0c4dd1da99afc92 to your computer and use it in GitHub Desktop.
Save LongHairedHacker/b66319e49b4789c2b0c4dd1da99afc92 to your computer and use it in GitHub Desktop.
fn convert_f32<'a>(input: &'a Vec<f32>) -> Box<Iterator<Item=f32> + 'a> {
Box::new(input.iter().cloned())
}
fn convert_u32<'a>(input: &'a Vec<u32>) -> Box<Iterator<Item=f32> + 'a> {
Box::new(input.iter().cloned().map(|x| x as f32))
}
enum InputType {
Float,
Int
}
fn main() {
let a : InputType = InputType::Float;
let vec_u: Vec<u32> = vec![1, 2, 3];
let vec_f: Vec<f32> = vec![1.5, 2.5, 3.5];
let x = match a {
InputType::Int => convert_u32(&vec_u),
_ => convert_f32(&vec_f)
};
for i in x {
println!("{}", i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment