nand2tetris/assembler/assembler.rs

32 lines
838 B
Rust

use std::env;
use std::fs::File;
use std::io::{self, BufRead};
use std::path::Path;
fn main() {
let args: Vec<String> = env::args().collect();
let filename = parse_config(&args);
if let Ok(lines) = read_lines(Path::new(filename)) {
// Consumes the iterator, returns an (Optional) String
for line in lines {
if let Ok(ip) = line {
println!("{}", ip);
}
}
}
}
fn parse_config(args: &[String]) -> &str {
let filename = &args[1];
filename
}
// The output is wrapped in a Result to allow matching on errors
// Returns an Iterator to the Reader of the lines of the file.
fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
where P: AsRef<Path>, {
let file = File::open(filename)?;
Ok(io::BufReader::new(file).lines())
}