This commit is contained in:
Argon 2022-09-14 18:43:49 +08:00
parent 8f063efbbe
commit dcd876a636
1 changed files with 26 additions and 0 deletions

View File

@ -1,3 +1,29 @@
use std::{fs, io::{self, BufRead, BufReader}};
fn main() { fn main() {
println!("Hello, world!"); println!("Hello, world!");
} }
fn read_codes(code_file : &str) -> io::Result<Vec<u32>> {
let file = fs::File::open(code_file)?;
let reader = BufReader::new(file);
let mut codes = Vec::new();
let mut line_count = 0;
for line in reader.lines() {
if let Ok(l) = line {
let r_str = l.as_str();
let code_vec : Vec<&str> = r_str.split(' ').collect();
if code_vec.len() == 2 {
let val1 : u32 = code_vec[0].parse().unwrap_or_default();
let val2 : u32 = code_vec[1].parse().unwrap_or_default();
codes.push(val1);
codes.push(val2);
} else {
println!("code error at line {}.", line_count);
}
}
line_count += 1;
}
Ok(codes)
}