Created
June 6, 2016 20:14
-
-
Save gsquire/1b09c5b915a1be8e95153d34a5399724 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::env; | |
use std::io; | |
use std::io::prelude::*; | |
use std::fs::File; | |
fn cat(f: &String) -> io::Result<String> { | |
let mut f = try!(File::open(f)); | |
let mut contents = String::new(); | |
try!(f.read_to_string(&mut contents)); | |
Ok(contents) | |
} | |
fn main() { | |
let file_name = env::args().nth(1); | |
match file_name { | |
Some(f) => { | |
let contents = cat(&f); | |
if contents.is_ok() { | |
print!("{}", contents.unwrap()); | |
} else { | |
println!("error for file {}: {}", f, contents.unwrap_err()); | |
} | |
} | |
None => { println!("must supply 1 file..."); } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment