Created
December 22, 2015 16:19
-
-
Save anonymous/ea04b8ecf30d8ef36d06 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashMap; | |
use std::io; | |
use std::io::prelude::*; | |
use std::io::BufReader; | |
use std::fs::File; | |
use std::error::Error; | |
use std::mem; | |
use std::str; | |
type Something<'a> = HashMap<&'a str, &'a str>; | |
fn getLines(filename: &str) -> Result<io::Lines<BufReader<File>>, io::Error> { | |
let mut f = try!(File::open(filename)); | |
Ok(BufReader::new(f).lines()) | |
} | |
fn getSomething<'a>() -> Result<&'a Something<'a>, io::Error> { | |
let mut something = Something::new(); | |
try!(getLines("gates.txt")) | |
.map(|line| line.unwrap().as_ref()) | |
.map(|line| something.insert(line, line)); | |
Ok(&something) | |
} | |
fn main() { | |
match getSomething() { | |
Ok(something) => println!("Values: (yay, {})", something.get("yay").unwrap()), | |
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