Merge 8cabe40643
into 3b541898e2
This commit is contained in:
commit
be4ee16fab
|
@ -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())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue