diff options
| author | Jokler <jokler.contact@gmail.com> | 2017-10-18 15:42:00 +0200 |
|---|---|---|
| committer | Jokler <jokler.contact@gmail.com> | 2017-10-18 15:42:00 +0200 |
| commit | 8c51489bdd2d0c383c7d5b8e490cf2728702ba7b (patch) | |
| tree | 28c225ca3910e3f1cb996692e004512cffdf7947 /src | |
| parent | 8802b4a2839cb2e4d4cd2ed3d3e1b27ae4b250e6 (diff) | |
| download | frippy-8c51489bdd2d0c383c7d5b8e490cf2728702ba7b.tar.gz frippy-8c51489bdd2d0c383c7d5b8e490cf2728702ba7b.zip | |
Pass on a Result from the Currency eval function
Diffstat (limited to 'src')
| -rw-r--r-- | src/plugins/currency.rs | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/plugins/currency.rs b/src/plugins/currency.rs index 62ba847..b15c852 100644 --- a/src/plugins/currency.rs +++ b/src/plugins/currency.rs @@ -4,8 +4,11 @@ extern crate serde_json; extern crate regex; use std::io::Read; +use std::num::ParseFloatError; + use irc::client::prelude::*; use irc::error::Error as IrcError; + use self::reqwest::Client; use self::reqwest::header::Connection; use self::serde_json::Value; @@ -66,16 +69,12 @@ impl Currency { Currency {} } - fn eval_command<'a>(&self, tokens: &'a [String]) -> Option<ConvertionRequest<'a>> { - if let Some(parsed) = tokens[0].parse().ok() { - Some(ConvertionRequest { - value: parsed, - source: &tokens[1], - target: &tokens[2], - }) - } else { - None - } + fn eval_command<'a>(&self, tokens: &'a [String]) -> Result<ConvertionRequest<'a>, ParseFloatError> { + Ok(ConvertionRequest { + value: tokens[0].parse()?, + source: &tokens[1], + target: &tokens[2], + }) } fn convert(&self, server: &IrcServer, command: PluginCommand) -> Result<(), IrcError> { @@ -85,8 +84,8 @@ impl Currency { } let request = match self.eval_command(&command.tokens) { - Some(request) => request, - None => { + Ok(request) => request, + Err(_) => { return self.invalid_command(server, &command); } }; |
