Skip to content

Instantly share code, notes, and snippets.

Created December 22, 2015 17:03
Show Gist options
  • Save anonymous/76365613f320a56d6ab9 to your computer and use it in GitHub Desktop.
Save anonymous/76365613f320a56d6ab9 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
use std::io;
use std::io::prelude::*;
use std::io::BufReader;
use std::fs::File;
fn get_line_vec(filename: &str) -> Result<&mut Vec<String>, io::Error> {
let mut vec: Vec<String> = Vec::new();
let mut f = try!(File::open(filename));
BufReader::new(f).lines()
.map(|line| vec.push(line.unwrap()));
Ok(&mut vec)
}
fn main(){
match get_line_vec("yay.txt") {
Ok(vec) => {
let a = vec.pop().unwrap();
println!("{}", a);
},
Err(e) => {
println!("Error: {}", e.to_string())
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment