Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.