mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Use try syntax for Option where appropriate
This commit is contained in:
parent
fe16c1d5c3
commit
2d45e9d2da
19 changed files with 65 additions and 180 deletions
|
@ -16,22 +16,13 @@ lazy_static! {
|
|||
}
|
||||
|
||||
fn create_host_table() -> Option<HashMap<String, IpAddr>> {
|
||||
// TODO: handle bad file path
|
||||
let path = match env::var("HOST_FILE") {
|
||||
Ok(host_file_path) => host_file_path,
|
||||
Err(_) => return None,
|
||||
};
|
||||
let path = env::var_os("HOST_FILE")?;
|
||||
|
||||
let mut file = match File::open(&path) {
|
||||
Ok(f) => BufReader::new(f),
|
||||
Err(_) => return None,
|
||||
};
|
||||
let file = File::open(&path).ok()?;
|
||||
let mut reader = BufReader::new(file);
|
||||
|
||||
let mut lines = String::new();
|
||||
match file.read_to_string(&mut lines) {
|
||||
Ok(_) => (),
|
||||
Err(_) => return None,
|
||||
};
|
||||
reader.read_to_string(&mut lines).ok()?;
|
||||
|
||||
Some(parse_hostsfile(&lines))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue