summaryrefslogtreecommitdiffstats
path: root/src/plugins/remind
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2018-06-16 15:35:49 +0200
committerJokler <jokler.contact@gmail.com>2018-06-16 15:35:49 +0200
commit9baade2a5d9fec54fe4d88216fbdb91c154ad348 (patch)
treee4bee7605f2c2738574ad7d7a671c8b843bf53b5 /src/plugins/remind
parent768fcc68af3cc57f52ac7117cbf325479836159a (diff)
downloadfrippy-9baade2a5d9fec54fe4d88216fbdb91c154ad348.tar.gz
frippy-9baade2a5d9fec54fe4d88216fbdb91c154ad348.zip
Fix clippy warnings
Diffstat (limited to 'src/plugins/remind')
-rw-r--r--src/plugins/remind/database.rs14
-rw-r--r--src/plugins/remind/mod.rs21
-rw-r--r--src/plugins/remind/parser.rs50
3 files changed, 37 insertions, 48 deletions
diff --git a/src/plugins/remind/database.rs b/src/plugins/remind/database.rs
index e434ec0..97d93e8 100644
--- a/src/plugins/remind/database.rs
+++ b/src/plugins/remind/database.rs
@@ -1,5 +1,5 @@
-use std::collections::HashMap;
use std::collections::hash_map::Entry;
+use std::collections::HashMap;
use std::fmt;
#[cfg(feature = "mysql")]
@@ -66,7 +66,7 @@ pub trait Database: Send + Sync {
}
// HashMap
-impl Database for HashMap<i64, Event> {
+impl<S: ::std::hash::BuildHasher + Send + Sync> Database for HashMap<i64, Event, S> {
fn insert_event(&mut self, event: &NewEvent) -> Result<i64, RemindError> {
let mut id = 0;
while self.contains_key(&id) {
@@ -74,11 +74,11 @@ impl Database for HashMap<i64, Event> {
}
let event = Event {
- id: id,
+ id,
receiver: event.receiver.to_owned(),
content: event.content.to_owned(),
author: event.author.to_owned(),
- time: event.time.clone(),
+ time: *event.time,
repeat: event.repeat,
};
@@ -103,7 +103,7 @@ impl Database for HashMap<i64, Event> {
let mut events = Vec::new();
for (_, event) in self.iter() {
- if &event.time < time {
+ if event.time < *time {
events.push(event.clone())
}
}
@@ -132,9 +132,7 @@ impl Database for HashMap<i64, Event> {
}
fn get_event(&self, id: i64) -> Result<Event, RemindError> {
- Ok(self.get(&id)
- .map(|ev| ev.clone())
- .ok_or(ErrorKind::NotFound)?)
+ Ok(self.get(&id).cloned().ok_or(ErrorKind::NotFound)?)
}
fn delete_event(&mut self, id: i64) -> Result<(), RemindError> {
diff --git a/src/plugins/remind/mod.rs b/src/plugins/remind/mod.rs
index fada1fb..fa7cf70 100644
--- a/src/plugins/remind/mod.rs
+++ b/src/plugins/remind/mod.rs
@@ -98,7 +98,7 @@ impl<T: 'static + Database> Remind<T> {
let events = Arc::new(RwLock::new(db));
Remind {
- events: events,
+ events,
has_reminder: RwLock::new(false),
}
}
@@ -106,17 +106,17 @@ impl<T: 'static + Database> Remind<T> {
fn user_cmd(&self, command: PluginCommand) -> Result<String, RemindError> {
let parser = CommandParser::parse_target(command.tokens)?;
- self.set(parser, &command.source)
+ self.set(&parser, &command.source)
}
fn me_cmd(&self, command: PluginCommand) -> Result<String, RemindError> {
let source = command.source.clone();
let parser = CommandParser::with_target(command.tokens, command.source)?;
- self.set(parser, &source)
+ self.set(&parser, &source)
}
- fn set(&self, parser: CommandParser, author: &str) -> Result<String, RemindError> {
+ fn set(&self, parser: &CommandParser, author: &str) -> Result<String, RemindError> {
debug!("parser: {:?}", parser);
let target = parser.get_target();
@@ -125,7 +125,7 @@ impl<T: 'static + Database> Remind<T> {
let event = database::NewEvent {
receiver: target,
content: &parser.get_message(),
- author: author,
+ author,
time: &time,
repeat: parser
.get_repeat(Duration::from_secs(600))?
@@ -212,9 +212,10 @@ impl<T: Database> Plugin for Remind<T> {
fn command(&self, client: &IrcClient, mut command: PluginCommand) -> Result<(), FrippyError> {
if command.tokens.is_empty() {
- return Ok(client
+ client
.send_notice(&command.source, &ErrorKind::InvalidCommand.to_string())
- .context(FrippyErrorKind::Connection)?);
+ .context(FrippyErrorKind::Connection)?;
+ return Ok(());
}
let source = command.source.clone();
@@ -229,7 +230,7 @@ impl<T: Database> Plugin for Remind<T> {
_ => Err(ErrorKind::InvalidCommand.into()),
};
- let result = match response {
+ match response {
Ok(msg) => client
.send_notice(&source, &msg)
.context(FrippyErrorKind::Connection)?,
@@ -242,9 +243,9 @@ impl<T: Database> Plugin for Remind<T> {
Err(e).context(FrippyErrorKind::Remind)?
}
- };
+ }
- Ok(result)
+ Ok(())
}
fn evaluate(&self, _: &IrcClient, _: PluginCommand) -> Result<String, String> {
diff --git a/src/plugins/remind/parser.rs b/src/plugins/remind/parser.rs
index eb39d04..d6e8574 100644
--- a/src/plugins/remind/parser.rs
+++ b/src/plugins/remind/parser.rs
@@ -99,36 +99,26 @@ impl CommandParser {
use self::ParseState::*;
let string = Some(string);
match state {
- &On if self.on_date.is_none() => {
- return Ok(CommandParser {
- on_date: string,
- ..self
- })
- }
- &At if self.at_time.is_none() => {
- return Ok(CommandParser {
- at_time: string,
- ..self
- })
- }
- &In if self.in_duration.is_none() => {
- return Ok(CommandParser {
- in_duration: string,
- ..self
- })
- }
- &Msg if self.message.is_none() => {
- return Ok(CommandParser {
- message: string,
- ..self
- })
- }
- &Every if self.every_time.is_none() => {
- return Ok(CommandParser {
- every_time: string,
- ..self
- })
- }
+ On if self.on_date.is_none() => Ok(CommandParser {
+ on_date: string,
+ ..self
+ }),
+ At if self.at_time.is_none() => Ok(CommandParser {
+ at_time: string,
+ ..self
+ }),
+ In if self.in_duration.is_none() => Ok(CommandParser {
+ in_duration: string,
+ ..self
+ }),
+ Msg if self.message.is_none() => Ok(CommandParser {
+ message: string,
+ ..self
+ }),
+ Every if self.every_time.is_none() => Ok(CommandParser {
+ every_time: string,
+ ..self
+ }),
_ => Err(ErrorKind::MissingMessage.into()),
}
}