From 2dfd8abfc149962a4601d4362d978d85af1c8eaa Mon Sep 17 00:00:00 2001 From: Anders Olsson Date: Tue, 18 Dec 2018 14:43:13 +0100 Subject: [PATCH] Fmt. --- src/context.rs | 12 +++++++----- src/probe/eniro.rs | 6 +++--- src/probe/hitta.rs | 6 +++--- src/probe/konsument_info.rs | 17 ++++++++++------- src/probe/telefonforsaljare.rs | 17 ++++++++++------- src/probe/vem_ringde.rs | 6 +++--- 6 files changed, 36 insertions(+), 28 deletions(-) diff --git a/src/context.rs b/src/context.rs index a9cd73b..6d2cbe3 100644 --- a/src/context.rs +++ b/src/context.rs @@ -2,7 +2,7 @@ use std::fs; use std::io; use directories::ProjectDirs; -use serde_derive::{Serialize, Deserialize}; +use serde_derive::{Deserialize, Serialize}; #[derive(Serialize, Deserialize)] pub struct Cache { @@ -27,8 +27,9 @@ impl Context { if cache.exists() { fs::File::open(cache) .and_then(|file| { - bincode::deserialize_from(&file) - .map_err(|_| io::Error::new(io::ErrorKind::Other, "failed to deserialize cache entry")) + bincode::deserialize_from(&file).map_err(|_| { + io::Error::new(io::ErrorKind::Other, "failed to deserialize cache entry") + }) }) .ok() } else { @@ -59,8 +60,9 @@ impl Context { .truncate(true) .open(cache) .and_then(|mut file| { - bincode::serialize_into(&mut file, &entry) - .map_err(|_| io::Error::new(io::ErrorKind::Other, "failed to serialize cache entry")) + bincode::serialize_into(&mut file, &entry).map_err(|_| { + io::Error::new(io::ErrorKind::Other, "failed to serialize cache entry") + }) }) } } diff --git a/src/probe/eniro.rs b/src/probe/eniro.rs index 6ab7cb7..e60099f 100644 --- a/src/probe/eniro.rs +++ b/src/probe/eniro.rs @@ -7,8 +7,7 @@ pub struct Eniro; impl Probe for Eniro { fn search(&mut self, ctx: &mut Context, number: &str) { let body = if let Some(cache) = ctx.cache_get("eniro", &number) { - String::from_utf8(cache.data) - .unwrap() + String::from_utf8(cache.data).unwrap() } else { reqwest::get(&format!("https://gulasidorna.eniro.se/hitta:{}", number)) .unwrap() @@ -16,6 +15,7 @@ impl Probe for Eniro { .unwrap() }; - ctx.cache_set("eniro", &number, body.as_bytes()).expect("wut?! why not?!"); + ctx.cache_set("eniro", &number, body.as_bytes()) + .expect("wut?! why not?!"); } } diff --git a/src/probe/hitta.rs b/src/probe/hitta.rs index 92d976a..08dc3f2 100644 --- a/src/probe/hitta.rs +++ b/src/probe/hitta.rs @@ -9,8 +9,7 @@ pub struct Hitta; impl Probe for Hitta { fn search(&mut self, ctx: &mut Context, number: &str) { let body = if let Some(cache) = ctx.cache_get("hitta", &number) { - String::from_utf8(cache.data) - .unwrap() + String::from_utf8(cache.data).unwrap() } else { reqwest::get(&format!("https://www.hitta.se/vem-ringde/{}", number)) .unwrap() @@ -18,7 +17,8 @@ impl Probe for Hitta { .unwrap() }; - ctx.cache_set("hitta", &number, body.as_bytes()).expect("wut?! why not?!"); + ctx.cache_set("hitta", &number, body.as_bytes()) + .expect("wut?! why not?!"); let document = Html::parse_document(&body); diff --git a/src/probe/konsument_info.rs b/src/probe/konsument_info.rs index c37d063..1f10d61 100644 --- a/src/probe/konsument_info.rs +++ b/src/probe/konsument_info.rs @@ -7,15 +7,18 @@ pub struct KonsumentInfo; impl Probe for KonsumentInfo { fn search(&mut self, ctx: &mut Context, number: &str) { let body = if let Some(cache) = ctx.cache_get("konsument_info", &number) { - String::from_utf8(cache.data) - .unwrap() + String::from_utf8(cache.data).unwrap() } else { - reqwest::get(&format!("http://konsumentinfo.se/telefonnummer/sverige/{}", number)) - .unwrap() - .text() - .unwrap() + reqwest::get(&format!( + "http://konsumentinfo.se/telefonnummer/sverige/{}", + number + )) + .unwrap() + .text() + .unwrap() }; - ctx.cache_set("konsument_info", &number, body.as_bytes()).expect("wut?! why not?!"); + ctx.cache_set("konsument_info", &number, body.as_bytes()) + .expect("wut?! why not?!"); } } diff --git a/src/probe/telefonforsaljare.rs b/src/probe/telefonforsaljare.rs index 9e22477..0a10b5a 100644 --- a/src/probe/telefonforsaljare.rs +++ b/src/probe/telefonforsaljare.rs @@ -7,15 +7,18 @@ pub struct Telefonforsaljare; impl Probe for Telefonforsaljare { fn search(&mut self, ctx: &mut Context, number: &str) { let body = if let Some(cache) = ctx.cache_get("telefonforsaljare", &number) { - String::from_utf8(cache.data) - .unwrap() + String::from_utf8(cache.data).unwrap() } else { - reqwest::get(&format!("http://www.telefonforsaljare.nu/telefonnummer/{}/", number)) - .unwrap() - .text() - .unwrap() + reqwest::get(&format!( + "http://www.telefonforsaljare.nu/telefonnummer/{}/", + number + )) + .unwrap() + .text() + .unwrap() }; - ctx.cache_set("telefonforsaljare", &number, body.as_bytes()).expect("wut?! why not?!"); + ctx.cache_set("telefonforsaljare", &number, body.as_bytes()) + .expect("wut?! why not?!"); } } diff --git a/src/probe/vem_ringde.rs b/src/probe/vem_ringde.rs index be72f1f..6b88618 100644 --- a/src/probe/vem_ringde.rs +++ b/src/probe/vem_ringde.rs @@ -7,8 +7,7 @@ pub struct VemRingde; impl Probe for VemRingde { fn search(&mut self, ctx: &mut Context, number: &str) { let body = if let Some(cache) = ctx.cache_get("vem_ringde", &number) { - String::from_utf8(cache.data) - .unwrap() + String::from_utf8(cache.data).unwrap() } else { reqwest::get(&format!("http://vemringde.se/?q={}", number)) .unwrap() @@ -16,6 +15,7 @@ impl Probe for VemRingde { .unwrap() }; - ctx.cache_set("vem_ringde", &number, body.as_bytes()).expect("wut?! why not?!"); + ctx.cache_set("vem_ringde", &number, body.as_bytes()) + .expect("wut?! why not?!"); } }