Like my first immersion in Rust after a while, I started writing code to upload the contents of the file to a string, for further processing (now I just print it)
Is there a cleaner way to do this than I am now? It seems like I need to be too detailed, but I don't see any good ways to clean it.
use std::io; use std::io::File; use std::os; use std::str; fn main() { println!("meh"); let filename = &os::args()[1]; let contents = match File::open(&Path::new(filename)).read_to_end() { Ok(s) => str::from_utf8(s.as_slice()).expect("this shouldn't happen").to_string(), Err(e) => "".to_string(), }; println!("ugh {}", contents.to_string()); }
Earlz source share