diff options
| author | Jokler <jokler.contact@gmail.com> | 2018-02-13 16:18:42 +0100 |
|---|---|---|
| committer | Jokler <jokler.contact@gmail.com> | 2018-02-13 16:18:42 +0100 |
| commit | 968c837365c4a332fe3c802fd4ecab2562eb4d5a (patch) | |
| tree | 4ad922c19536fcf4630c4cae624946cfadea66ef /src/plugins/currency.rs | |
| parent | d08eb3db79e702a729324e06ed8f6ab86c8355e3 (diff) | |
| download | frippy-968c837365c4a332fe3c802fd4ecab2562eb4d5a.tar.gz frippy-968c837365c4a332fe3c802fd4ecab2562eb4d5a.zip | |
Replace try_option with ?
Diffstat (limited to 'src/plugins/currency.rs')
| -rw-r--r-- | src/plugins/currency.rs | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/src/plugins/currency.rs b/src/plugins/currency.rs index 393df9b..958c8e2 100644 --- a/src/plugins/currency.rs +++ b/src/plugins/currency.rs @@ -23,15 +23,6 @@ struct ConvertionRequest<'a> { target: &'a str, } -macro_rules! try_option { - ($e:expr) => { - match $e { - Some(v) => v, - None => { return None; } - } - } -} - impl<'a> ConvertionRequest<'a> { fn send(&self) -> Option<f64> { let response = Client::new() @@ -43,15 +34,14 @@ impl<'a> ConvertionRequest<'a> { match response { Ok(mut response) => { let mut body = String::new(); - try_option!(response.read_to_string(&mut body).ok()); + response.read_to_string(&mut body).ok()?; let convertion_rates: Result<Value, _> = serde_json::from_str(&body); match convertion_rates { Ok(convertion_rates) => { - let rates: &Value = try_option!(convertion_rates.get("rates")); - let target_rate: &Value = - try_option!(rates.get(self.target.to_uppercase())); - Some(self.value * try_option!(target_rate.as_f64())) + let rates: &Value = convertion_rates.get("rates")?; + let target_rate: &Value = rates.get(self.target.to_uppercase())?; + Some(self.value * target_rate.as_f64()?) } Err(_) => None, } |
