Skip to content

Instantly share code, notes, and snippets.

@gsquire
Created June 6, 2016 20:14
Show Gist options
  • Save gsquire/1b09c5b915a1be8e95153d34a5399724 to your computer and use it in GitHub Desktop.
Save gsquire/1b09c5b915a1be8e95153d34a5399724 to your computer and use it in GitHub Desktop.
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