Skip to content

Instantly share code, notes, and snippets.

@grahamking
Created April 26, 2013 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grahamking/5469290 to your computer and use it in GitHub Desktop.
Save grahamking/5469290 to your computer and use it in GitHub Desktop.
Rust: Load a file v2
fn load(filename: ~str) -> ~[~str] {
// The simple way:
// let read_result = io::file_reader(~path::Path(filename));
let read_result: Result<@Reader, ~str>;
read_result = io::file_reader(~path::Path(filename));
match read_result {
Ok(file) => return file.read_lines(),
Err(e) => {
println(fmt!("Error reading file: %?", e));
return ~[];
}
}
}
fn main() {
let contents = load(~"myfile.txt");
println(fmt!("%?", contents));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment