From 2d45e9d2da571e70deef137f9022de87cc1126f3 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Fri, 20 Oct 2017 08:25:35 -0700 Subject: Use try syntax for Option where appropriate --- components/net/hosts.rs | 17 ++++------------- components/net/http_loader.rs | 5 +---- 2 files changed, 5 insertions(+), 17 deletions(-) (limited to 'components/net') diff --git a/components/net/hosts.rs b/components/net/hosts.rs index 768108052e7..06e58fab3b9 100644 --- a/components/net/hosts.rs +++ b/components/net/hosts.rs @@ -16,22 +16,13 @@ lazy_static! { } fn create_host_table() -> Option> { - // 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)) } diff --git a/components/net/http_loader.rs b/components/net/http_loader.rs index e3972f6c0f3..c7b15d785ed 100644 --- a/components/net/http_loader.rs +++ b/components/net/http_loader.rs @@ -108,10 +108,7 @@ impl WrappedHttpResponse { } fn content_encoding(&self) -> Option { - let encodings = match self.headers().get::() { - Some(&ContentEncoding(ref encodings)) => encodings, - None => return None, - }; + let &ContentEncoding(ref encodings) = self.headers().get()?; if encodings.contains(&Encoding::Gzip) { Some(Encoding::Gzip) } else if encodings.contains(&Encoding::Deflate) { -- cgit v1.2.3