Created
November 23, 2016 20:02
-
-
Save LongHairedHacker/b66319e49b4789c2b0c4dd1da99afc92 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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