Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust Implementation #1

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions assembler/assembler.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
use std::fs::File;
use std::env;
use std::fs::File;
use std::io::{self, BufRead};
use std::path::Path;
fn main() -> std::io::Result<()> {
let fileName = env::args().nth(1);
let fileLines = read_lines(fileName);
Ok(())

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())
}