Hi All!
I just started to explore Rust, and have created a very tiny program, which reads in a lot of (100k) numbers from a file (one number per line).
It looks like this:
fn main() {
let path = Path::new("numbers.txt");
let mut fileReader = BufferedReader::new(File::open(&path));
let mut vector: Vec<isize> = vec![];
for line in fileReader.lines() {
match line {
Err(why) => panic!("{:?}", why),
Ok(string) => match string.trim().parse::<isize>() {
None => panic!("Not a number!"),
Some(number)=> vector.push(number)
}
}
}
}
So basically, I read the file line by line then convert every line to a number.
I've created the same program in Go and Python and they seem to be somewhat faster (go nearly about 20%, python about 50%).
Of course, all of them are quite fast so it's not a big deal, I just wonder whether I took the right approach (i.e. I'm doing things in the "rusty" way :-)).
I also understand that I use a few unstable features and as I've read the IO is still subject to change.
The version I use is: rustc 1.0.0-nightly (c5961ad06 2015-01-28 21:49:38 +0000)
So, the question is: am I on the right track, or there are some possibilities to tweak this method a bit more?
Thanks in advance!
Cheers!