From 6a4e52b3fac7d2e96e3a1a67901fbdd4721fb249 Mon Sep 17 00:00:00 2001 From: acdenisSK Date: Mon, 2 Oct 2017 22:29:10 +0200 Subject: Use the de-generification trick. Fixes #168 --- src/framework/standard/mod.rs | 47 ++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) (limited to 'src/framework') diff --git a/src/framework/standard/mod.rs b/src/framework/standard/mod.rs index 92572dd..682a466 100644 --- a/src/framework/standard/mod.rs +++ b/src/framework/standard/mod.rs @@ -236,10 +236,9 @@ impl StandardFramework { /// .bucket("basic") /// .exec_str("pong!"))); /// ``` - pub fn bucket(mut self, s: S, delay: i64, time_span: i64, limit: i32) -> Self - where S: Into { + pub fn bucket(mut self, s: &str, delay: i64, time_span: i64, limit: i32) -> Self { self.buckets.insert( - s.into(), + s.to_string(), Bucket { ratelimit: Ratelimit { delay: delay, @@ -282,8 +281,8 @@ impl StandardFramework { /// /// [`bucket`]: #method.bucket #[cfg(feature = "cache")] - pub fn complex_bucket(mut self, - s: S, + pub fn complex_bucket(mut self, + s: &str, delay: i64, time_span: i64, limit: i32, @@ -292,10 +291,9 @@ impl StandardFramework { where Check: Fn(&mut Context, Option, ChannelId, UserId) -> bool + Send + Sync - + 'static, - S: Into { + + 'static { self.buckets.insert( - s.into(), + s.to_string(), Bucket { ratelimit: Ratelimit { delay, @@ -336,17 +334,16 @@ impl StandardFramework { /// /// [`bucket`]: #method.bucket #[cfg(not(feature = "cache"))] - pub fn complex_bucket(mut self, - s: S, + pub fn complex_bucket(mut self, + s: &str, delay: i64, time_span: i64, limit: i32, check: Check) -> Self - where Check: Fn(&mut Context, ChannelId, UserId) -> bool + Send + Sync + 'static, - S: Into { + where Check: Fn(&mut Context, ChannelId, UserId) -> bool + Send + Sync + 'static { self.buckets.insert( - s.into(), + s.to_string(), Bucket { ratelimit: Ratelimit { delay, @@ -381,10 +378,9 @@ impl StandardFramework { /// .bucket("simple") /// .exec_str("pong!"))); /// ``` - pub fn simple_bucket(mut self, s: S, delay: i64) -> Self - where S: Into { + pub fn simple_bucket(mut self, s: &str, delay: i64) -> Self { self.buckets.insert( - s.into(), + s.to_string(), Bucket { ratelimit: Ratelimit { delay: delay, @@ -596,20 +592,17 @@ impl StandardFramework { /// }); /// # } /// ``` - pub fn on(mut self, command_name: S, f: F) -> Self - where F: Fn(&mut Context, &Message, Args) -> Result<(), CommandError> + Send + Sync + 'static, - S: Into { + pub fn on(mut self, command_name: &str, f: F) -> Self + where F: Fn(&mut Context, &Message, Args) -> Result<(), CommandError> + Send + Sync + 'static { { let ungrouped = self.groups .entry("Ungrouped".to_string()) .or_insert_with(|| Arc::new(CommandGroup::default())); if let Some(ref mut group) = Arc::get_mut(ungrouped) { - let name = command_name.into(); - group .commands - .insert(name, CommandOrAlias::Command(Arc::new(Command::new(f)))); + .insert(command_name.to_string(), CommandOrAlias::Command(Arc::new(Command::new(f)))); } } @@ -629,8 +622,8 @@ impl StandardFramework { /// let _ = ctx.say("pong"); /// })); /// ``` - pub fn command(mut self, command_name: S, f: F) -> Self - where F: FnOnce(CreateCommand) -> CreateCommand, S: Into { + pub fn command(mut self, command_name: &str, f: F) -> Self + where F: FnOnce(CreateCommand) -> CreateCommand { { let ungrouped = self.groups .entry("Ungrouped".to_string()) @@ -638,7 +631,7 @@ impl StandardFramework { if let Some(ref mut group) = Arc::get_mut(ungrouped) { let cmd = f(CreateCommand(Command::default())).0; - let name = command_name.into(); + let name = command_name.to_string(); if let Some(ref prefix) = group.prefix { for v in &cmd.aliases { @@ -688,8 +681,8 @@ impl StandardFramework { /// .command("ping", |c| c.exec_str("pong!")) /// .command("pong", |c| c.exec_str("ping!")))); /// ``` - pub fn group(mut self, group_name: S, f: F) -> Self - where F: FnOnce(CreateGroup) -> CreateGroup, S: Into { + pub fn group(mut self, group_name: &str, f: F) -> Self + where F: FnOnce(CreateGroup) -> CreateGroup { let group = f(CreateGroup(CommandGroup::default())).0; self.groups.insert(group_name.into(), Arc::new(group)); -- cgit v1.2.3