Add data for course 1 assignment 4
This commit is contained in:
21
src/util.rs
Normal file
21
src/util.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
use std::fs::File;
|
||||
use std::io;
|
||||
use std::io::{BufRead, BufReader, Error, ErrorKind};
|
||||
use std::vec::Vec;
|
||||
|
||||
pub fn read_to_vector(path: &str) -> Result<Vec<i64>, io::Error> {
|
||||
let file = File::open(path)?;
|
||||
let br = BufReader::new(file);
|
||||
let mut v = Vec::new();
|
||||
for line in br.lines() {
|
||||
let line = line?;
|
||||
let n = line
|
||||
.trim()
|
||||
.parse()
|
||||
.map_err(|e| Error::new(ErrorKind::InvalidData, e))?;
|
||||
v.push(n);
|
||||
}
|
||||
Ok(v)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user