diff options
| author | acdenisSK <[email protected]> | 2017-10-03 16:55:58 +0200 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-10-09 15:47:48 -0700 |
| commit | 06dc6937bd3d4e5912de08e4ac3630a1f83b7f5a (patch) | |
| tree | eee16dc9d1c35e2b17a0a59d55cc85fa82726587 /src | |
| parent | Use the de-generification trick. (diff) | |
| download | serenity-06dc6937bd3d4e5912de08e4ac3630a1f83b7f5a.tar.xz serenity-06dc6937bd3d4e5912de08e4ac3630a1f83b7f5a.zip | |
Revert "Use the de-generification trick."
Makes the compiliation time just a bit worse
Diffstat (limited to 'src')
| -rw-r--r-- | src/builder/create_embed.rs | 16 | ||||
| -rw-r--r-- | src/builder/create_message.rs | 6 | ||||
| -rw-r--r-- | src/builder/edit_guild.rs | 27 | ||||
| -rw-r--r-- | src/builder/edit_member.rs | 8 | ||||
| -rw-r--r-- | src/builder/get_messages.rs | 24 | ||||
| -rw-r--r-- | src/cache/mod.rs | 52 | ||||
| -rw-r--r-- | src/framework/standard/mod.rs | 38 | ||||
| -rw-r--r-- | src/http/mod.rs | 6 | ||||
| -rw-r--r-- | src/model/channel/channel_id.rs | 61 | ||||
| -rw-r--r-- | src/model/channel/group.rs | 8 | ||||
| -rw-r--r-- | src/model/channel/message.rs | 6 | ||||
| -rw-r--r-- | src/model/channel/reaction.rs | 12 | ||||
| -rw-r--r-- | src/model/guild/guild_id.rs | 91 | ||||
| -rw-r--r-- | src/model/guild/member.rs | 22 | ||||
| -rw-r--r-- | src/model/guild/mod.rs | 30 | ||||
| -rw-r--r-- | src/model/invite.rs | 5 | ||||
| -rw-r--r-- | src/model/user.rs | 10 | ||||
| -rw-r--r-- | src/utils/message_builder.rs | 24 | ||||
| -rw-r--r-- | src/voice/manager.rs | 17 |
19 files changed, 117 insertions, 346 deletions
diff --git a/src/builder/create_embed.rs b/src/builder/create_embed.rs index 7303693..a128c91 100644 --- a/src/builder/create_embed.rs +++ b/src/builder/create_embed.rs @@ -62,20 +62,14 @@ impl CreateEmbed { /// [`colour`]: #method.colour #[cfg(feature = "utils")] #[inline] - pub fn color<C: Into<Colour>>(self, colour: C) -> Self { self.colour(colour) } + pub fn color<C: Into<Colour>>(self, colour: C) -> Self { self.colour(colour.into()) } - /// Set the colour of the left-hand side of the embed. #[cfg(feature = "utils")] pub fn colour<C: Into<Colour>>(mut self, colour: C) -> Self { - self._colour(colour.into()) - } - - #[cfg(feature = "utils")] - fn _colour(mut self, colour: Colour) -> Self { self.0.insert( "color".to_string(), - Value::Number(Number::from(colour.0 as u64)), + Value::Number(Number::from(colour.into().0 as u64)), ); CreateEmbed(self.0) @@ -288,12 +282,8 @@ impl CreateEmbed { /// let mut client = Client::new("token", Handler); client.start().unwrap(); /// ``` pub fn timestamp<T: Into<Timestamp>>(mut self, timestamp: T) -> Self { - self._timestamp(timestamp.into()) - } - - fn _timestamp(mut self, timestamp: Timestamp) -> Self { self.0 - .insert("timestamp".to_string(), Value::String(timestamp.ts)); + .insert("timestamp".to_string(), Value::String(timestamp.into().ts)); CreateEmbed(self.0) } diff --git a/src/builder/create_message.rs b/src/builder/create_message.rs index 123c0b5..96bad82 100644 --- a/src/builder/create_message.rs +++ b/src/builder/create_message.rs @@ -75,11 +75,7 @@ impl CreateMessage { /// Adds a list of reactions to create after the message's sent. pub fn reactions<R: Into<ReactionType>>(mut self, reactions: Vec<R>) -> Self { - self._reactions(reactions.into_iter().map(|r| r.into()).collect()) - } - - fn _reactions(mut self, reactions: Vec<ReactionType>) -> Self { - self.1 = Some(reactions); + self.1 = Some(reactions.into_iter().map(|r| r.into()).collect()); CreateMessage(self.0, self.1) } diff --git a/src/builder/edit_guild.rs b/src/builder/edit_guild.rs index a4f2c54..0719305 100644 --- a/src/builder/edit_guild.rs +++ b/src/builder/edit_guild.rs @@ -22,14 +22,13 @@ impl EditGuild { /// valid. /// /// [`afk_timeout`]: #method.afk_timeout - pub fn afk_channel<C: Into<ChannelId>>(self, channel: Option<C>) -> Self { - self._afk_channel(channel.map(|c| c.into())) - } - - fn _afk_channel(mut self, channel: Option<ChannelId>) -> Self { + pub fn afk_channel<C: Into<ChannelId>>(mut self, channel: Option<C>) -> Self { self.0.insert( "afk_channel_id".to_string(), - channel.map_or(Value::Null, |ChannelId(id)| Value::Number(Number::from(id))) + match channel { + Some(channel) => Value::Number(Number::from(channel.into().0)), + None => Value::Null, + }, ); self @@ -99,14 +98,10 @@ impl EditGuild { /// Transfers the ownership of the guild to another user by Id. /// /// **Note**: The current user must be the owner of the guild. - pub fn owner<U: Into<UserId>>(self, user_id: U) -> Self { - self._owner(user_id.into()) - } - - fn _owner(mut self, user_id: UserId) -> Self { + pub fn owner<U: Into<UserId>>(mut self, user_id: U) -> Self { self.0.insert( "owner_id".to_string(), - Value::Number(Number::from(user_id.0)), + Value::Number(Number::from(user_id.into().0)), ); self @@ -190,13 +185,9 @@ impl EditGuild { /// /// [`VerificationLevel`]: ../model/enum.VerificationLevel.html /// [`VerificationLevel::High`]: ../model/enum.VerificationLevel.html#variant.High - pub fn verification_level<V>(self, verification_level: V) -> Self + pub fn verification_level<V>(mut self, verification_level: V) -> Self where V: Into<VerificationLevel> { - self._verification_level(verification_level.into()) - } - - fn _verification_level(mut self, verification_level: VerificationLevel) -> Self { - let num = Value::Number(Number::from(verification_level.num())); + let num = Value::Number(Number::from(verification_level.into().num())); self.0.insert("verification_level".to_string(), num); diff --git a/src/builder/edit_member.rs b/src/builder/edit_member.rs index 53cf0d0..e450669 100644 --- a/src/builder/edit_member.rs +++ b/src/builder/edit_member.rs @@ -66,14 +66,10 @@ impl EditMember { /// Requires the [Move Members] permission. /// /// [Move Members]: ../model/permissions/constant.MOVE_MEMBERS.html - pub fn voice_channel<C: Into<ChannelId>>(self, channel_id: C) -> Self { - self._voice_channel(channel_id.into()) - } - - fn _voice_channel(mut self, channel_id: ChannelId) -> Self { + pub fn voice_channel<C: Into<ChannelId>>(mut self, channel_id: C) -> Self { self.0.insert( "channel_id".to_string(), - Value::Number(Number::from(channel_id.0)), + Value::Number(Number::from(channel_id.into().0)), ); self diff --git a/src/builder/get_messages.rs b/src/builder/get_messages.rs index eff90f4..71af9e5 100644 --- a/src/builder/get_messages.rs +++ b/src/builder/get_messages.rs @@ -55,36 +55,24 @@ pub struct GetMessages(pub BTreeMap<String, u64>); impl GetMessages { /// Indicates to retrieve the messages after a specific message, given by /// its Id. - pub fn after<M: Into<MessageId>>(self, message_id: M) -> Self { - self._after(message_id.into()) - } - - fn _after(mut self, MessageId(id): MessageId) -> Self { - self.0.insert("after".to_string(), id); + pub fn after<M: Into<MessageId>>(mut self, message_id: M) -> Self { + self.0.insert("after".to_string(), message_id.into().0); self } /// Indicates to retrieve the messages _around_ a specific message in either /// direction (before+after) the given message. - pub fn around<M: Into<MessageId>>(self, message_id: M) -> Self { - self._around(message_id.into()) - } - - fn _around(mut self, MessageId(id): MessageId) -> Self { - self.0.insert("around".to_string(), id); + pub fn around<M: Into<MessageId>>(mut self, message_id: M) -> Self { + self.0.insert("around".to_string(), message_id.into().0); self } /// Indicates to retrieve the messages before a specific message, given by /// its Id. - pub fn before<M: Into<MessageId>>(self, message_id: M) -> Self { - self._before(message_id.into()) - } - - fn _before(mut self, MessageId(id): MessageId) -> Self { - self.0.insert("before".to_string(), id); + pub fn before<M: Into<MessageId>>(mut self, message_id: M) -> Self { + self.0.insert("before".to_string(), message_id.into().0); self } diff --git a/src/cache/mod.rs b/src/cache/mod.rs index def6ac4..2bbc9bc 100644 --- a/src/cache/mod.rs +++ b/src/cache/mod.rs @@ -298,10 +298,8 @@ impl Cache { /// [`groups`]: #structfield.groups /// [`private_channels`]: #structfield.private_channels pub fn channel<C: Into<ChannelId>>(&self, id: C) -> Option<Channel> { - self._channel(id.into()) - } + let id = id.into(); - fn _channel(&self, id: ChannelId) -> Option<Channel> { if let Some(channel) = self.channels.get(&id) { return Some(Channel::Guild(channel.clone())); } @@ -348,11 +346,7 @@ impl Cache { /// ``` #[inline] pub fn guild<G: Into<GuildId>>(&self, id: G) -> Option<Arc<RwLock<Guild>>> { - self._guild(id.into()) - } - - fn _guild(&self, id: GuildId) -> Option<Arc<RwLock<Guild>>> { - self.guilds.get(&id).cloned() + self.guilds.get(&id.into()).cloned() } /// Retrieves a reference to a [`Guild`]'s channel. Unlike [`channel`], @@ -401,11 +395,7 @@ impl Cache { /// [`channel`]: #method.channel #[inline] pub fn guild_channel<C: Into<ChannelId>>(&self, id: C) -> Option<Arc<RwLock<GuildChannel>>> { - self._guild_channel(id.into()) - } - - fn _guild_channel(&self, id: ChannelId) -> Option<Arc<RwLock<GuildChannel>>> { - self.channels.get(&id).cloned() + self.channels.get(&id.into()).cloned() } /// Retrieves a reference to a [`Group`] from the cache based on the given @@ -441,11 +431,7 @@ impl Cache { /// ``` #[inline] pub fn group<C: Into<ChannelId>>(&self, id: C) -> Option<Arc<RwLock<Group>>> { - self._group(id.into()) - } - - fn _group(&self, id: ChannelId) -> Option<Arc<RwLock<Group>>> { - self.groups.get(&id).cloned() + self.groups.get(&id.into()).cloned() } /// Retrieves a [`Guild`]'s member from the cache based on the guild's and @@ -495,10 +481,6 @@ impl Cache { /// [`members`]: ../model/struct.Guild.html#structfield.members pub fn member<G, U>(&self, guild_id: G, user_id: U) -> Option<Member> where G: Into<GuildId>, U: Into<UserId> { - self._member(guild_id.into(), user_id.into()) - } - - fn _member(&self, guild_id: GuildId, user_id: UserId) -> Option<Member> { self.guilds.get(&guild_id.into()).and_then(|guild| { guild.read().unwrap().members.get(&user_id.into()).cloned() }) @@ -536,11 +518,7 @@ impl Cache { pub fn private_channel<C: Into<ChannelId>>(&self, channel_id: C) -> Option<Arc<RwLock<PrivateChannel>>> { - self._private_channel(channel_id.into()) - } - - fn _private_channel(&self, channel_id: ChannelId) -> Option<Arc<RwLock<PrivateChannel>>> { - self.private_channels.get(&channel_id).cloned() + self.private_channels.get(&channel_id.into()).cloned() } /// Retrieves a [`Guild`]'s role by their Ids. @@ -575,13 +553,9 @@ impl Cache { /// ``` pub fn role<G, R>(&self, guild_id: G, role_id: R) -> Option<Role> where G: Into<GuildId>, R: Into<RoleId> { - self._role(guild_id.into(), role_id.into()) - } - - fn _role(&self, guild_id: GuildId, role_id: RoleId) -> Option<Role> { self.guilds - .get(&guild_id) - .and_then(|g| g.read().unwrap().roles.get(&role_id).cloned()) + .get(&guild_id.into()) + .and_then(|g| g.read().unwrap().roles.get(&role_id.into()).cloned()) } /// Retrieves a `User` from the cache's [`users`] map, if it exists. @@ -616,22 +590,14 @@ impl Cache { /// ``` #[inline] pub fn user<U: Into<UserId>>(&self, user_id: U) -> Option<Arc<RwLock<User>>> { - self._user(user_id.into()) - } - - fn _user(&self, user_id: UserId) -> Option<Arc<RwLock<User>>> { - self.users.get(&user_id).cloned() + self.users.get(&user_id.into()).cloned() } #[inline] pub fn categories<C: Into<ChannelId>>(&self, channel_id: C) -> Option<Arc<RwLock<ChannelCategory>>> { - self._categories(channel_id.into()) - } - - fn _categories(&self, channel_id: ChannelId) -> Option<Arc<RwLock<ChannelCategory>>> { - self.categories.get(&channel_id).cloned() + self.categories.get(&channel_id.into()).cloned() } #[cfg(feature = "client")] diff --git a/src/framework/standard/mod.rs b/src/framework/standard/mod.rs index aa8a5e7..e735100 100644 --- a/src/framework/standard/mod.rs +++ b/src/framework/standard/mod.rs @@ -236,9 +236,10 @@ impl StandardFramework { /// .bucket("basic") /// .exec_str("pong!"))); /// ``` - pub fn bucket(mut self, s: &str, delay: i64, time_span: i64, limit: i32) -> Self { + pub fn bucket<S>(mut self, s: S, delay: i64, time_span: i64, limit: i32) -> Self + where S: Into<String> { self.buckets.insert( - s.to_string(), + s.into(), Bucket { ratelimit: Ratelimit { delay: delay, @@ -281,8 +282,8 @@ impl StandardFramework { /// /// [`bucket`]: #method.bucket #[cfg(feature = "cache")] - pub fn complex_bucket<Check>(mut self, - s: &str, + pub fn complex_bucket<S, Check>(mut self, + s: S, delay: i64, time_span: i64, limit: i32, @@ -291,9 +292,10 @@ impl StandardFramework { where Check: Fn(&mut Context, Option<GuildId>, ChannelId, UserId) -> bool + Send + Sync - + 'static { + + 'static, + S: Into<String> { self.buckets.insert( - s.to_string(), + s.into(), Bucket { ratelimit: Ratelimit { delay, @@ -334,16 +336,17 @@ impl StandardFramework { /// /// [`bucket`]: #method.bucket #[cfg(not(feature = "cache"))] - pub fn complex_bucket<Check>(mut self, - s: &str, + pub fn complex_bucket<S, Check>(mut self, + s: S, delay: i64, time_span: i64, limit: i32, check: Check) -> Self - where Check: Fn(&mut Context, ChannelId, UserId) -> bool + Send + Sync + 'static { + where Check: Fn(&mut Context, ChannelId, UserId) -> bool + Send + Sync + 'static, + S: Into<String> { self.buckets.insert( - s.to_string(), + s.into(), Bucket { ratelimit: Ratelimit { delay, @@ -378,9 +381,10 @@ impl StandardFramework { /// .bucket("simple") /// .exec_str("pong!"))); /// ``` - pub fn simple_bucket(mut self, s: &str, delay: i64) -> Self { + pub fn simple_bucket<S>(mut self, s: S, delay: i64) -> Self + where S: Into<String> { self.buckets.insert( - s.to_string(), + s.into(), Bucket { ratelimit: Ratelimit { delay: delay, @@ -623,8 +627,8 @@ impl StandardFramework { /// let _ = ctx.say("pong"); /// })); /// ``` - pub fn command<F>(mut self, command_name: &str, f: F) -> Self - where F: FnOnce(CreateCommand) -> CreateCommand { + pub fn command<F, S>(mut self, command_name: S, f: F) -> Self + where F: FnOnce(CreateCommand) -> CreateCommand, S: Into<String> { { let ungrouped = self.groups .entry("Ungrouped".to_string()) @@ -632,7 +636,7 @@ impl StandardFramework { if let Some(ref mut group) = Arc::get_mut(ungrouped) { let cmd = f(CreateCommand(Command::default())).0; - let name = command_name.to_string(); + let name = command_name.into(); if let Some(ref prefix) = group.prefix { for v in &cmd.aliases { @@ -682,8 +686,8 @@ impl StandardFramework { /// .command("ping", |c| c.exec_str("pong!")) /// .command("pong", |c| c.exec_str("ping!")))); /// ``` - pub fn group<F>(mut self, group_name: &str, f: F) -> Self - where F: FnOnce(CreateGroup) -> CreateGroup { + pub fn group<F, S>(mut self, group_name: S, f: F) -> Self + where F: FnOnce(CreateGroup) -> CreateGroup, S: Into<String> { let group = f(CreateGroup(CommandGroup::default())).0; self.groups.insert(group_name.into(), Arc::new(group)); diff --git a/src/http/mod.rs b/src/http/mod.rs index f7a71ee..4f70dcf 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -1613,10 +1613,6 @@ pub fn remove_group_recipient(group_id: u64, user_id: u64) -> Result<()> { /// [`HttpError::InvalidRequest`]: enum.HttpError.html#variant.InvalidRequest pub fn send_files<'a, T>(channel_id: u64, files: Vec<T>, map: JsonMap) -> Result<Message> where T: Into<AttachmentType<'a>> { - _send_files(channel_id, files.into_iter().map(|a| a.into()).collect(), map) -} - -fn _send_files<'a>(channel_id: u64, files: Vec<AttachmentType<'a>>, map: JsonMap) -> Result<Message> { let uri = format!(api!("/channels/{}/messages"), channel_id); let url = match Url::parse(&uri) { Ok(url) => url, @@ -1637,7 +1633,7 @@ fn _send_files<'a>(channel_id: u64, files: Vec<AttachmentType<'a>>, map: JsonMap let mut file_num = "0".to_string(); for file in files { - match file { + match file.into() { AttachmentType::Bytes((mut bytes, filename)) => { request .write_stream(&file_num, &mut bytes, Some(filename), None)?; diff --git a/src/model/channel/channel_id.rs b/src/model/channel/channel_id.rs index 04ed266..4cc997d 100644 --- a/src/model/channel/channel_id.rs +++ b/src/model/channel/channel_id.rs @@ -81,11 +81,7 @@ impl ChannelId { #[inline] pub fn create_reaction<M, R>(&self, message_id: M, reaction_type: R) -> Result<()> where M: Into<MessageId>, R: Into<ReactionType> { - self._create_reaction(message_id.into(), reaction_type.into()) - } - - fn _create_reaction(&self, MessageId(id): MessageId, reaction_type: ReactionType) -> Result<()> { - http::create_reaction(self.0, id, &reaction_type) + http::create_reaction(self.0, message_id.into().0, &reaction_type.into()) } /// Deletes this channel, returning the channel on a successful deletion. @@ -104,11 +100,7 @@ impl ChannelId { /// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html #[inline] pub fn delete_message<M: Into<MessageId>>(&self, message_id: M) -> Result<()> { - self._delete_message(message_id.into()) - } - - fn _delete_message(&self, MessageId(id): MessageId) -> Result<()> { - http::delete_message(self.0, id) + http::delete_message(self.0, message_id.into().0) } /// Deletes all messages by Ids from the given vector in the given channel. @@ -164,18 +156,11 @@ impl ChannelId { reaction_type: R) -> Result<()> where M: Into<MessageId>, R: Into<ReactionType> { - self._delete_reaction(message_id.into(), user_id, reaction_type.into()) - } - - fn _delete_reaction(&self, - MessageId(id): MessageId, - user_id: Option<UserId>, - reaction_type: ReactionType) -> Result<()> { http::delete_reaction( self.0, - id, + message_id.into().0, user_id.map(|uid| uid.0), - &reaction_type, + &reaction_type.into(), ) } @@ -224,11 +209,6 @@ impl ChannelId { /// [`the limit`]: ../builder/struct.CreateMessage.html#method.content pub fn edit_message<F, M>(&self, message_id: M, f: F) -> Result<Message> where F: FnOnce(CreateMessage) -> CreateMessage, M: Into<MessageId> { - self._edit_message(message_id.into(), f) - } - - fn _edit_message<F>(&self, MessageId(id): MessageId, f: F) -> Result<Message> - where F: FnOnce(CreateMessage) -> CreateMessage { let map = f(CreateMessage::default()).0; if let Some(content) = map.get("content") { @@ -239,7 +219,7 @@ impl ChannelId { } } - http::edit_message(self.0, id, &Value::Object(map)) + http::edit_message(self.0, message_id.into().0, &Value::Object(map)) } /// Search the cache for the channel with the Id. @@ -273,11 +253,7 @@ impl ChannelId { /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html #[inline] pub fn message<M: Into<MessageId>>(&self, message_id: M) -> Result<Message> { - self._message(message_id.into()) - } - - fn _message(&self, MessageId(id): MessageId) -> Result<Message> { - http::get_message(self.0, id) + http::get_message(self.0, message_id.into().0) .map(|mut msg| { msg.transform_content(); @@ -350,11 +326,7 @@ impl ChannelId { /// [`Message`]: struct.Message.html #[inline] pub fn pin<M: Into<MessageId>>(&self, message_id: M) -> Result<()> { - self._pin(message_id.into()) - } - - fn _pin(&self, MessageId(id): MessageId) -> Result<()> { - http::pin_message(self.0, id) + http::pin_message(self.0, message_id.into().0) } /// Gets the list of [`Message`]s which are pinned to the channel. @@ -382,23 +354,14 @@ impl ChannelId { after: Option<U>) -> Result<Vec<User>> where M: Into<MessageId>, R: Into<ReactionType>, U: Into<UserId> { - self._reaction_users(message_id.into(), reaction_type.into(), limit, after.map(|u| u.into())) - } - - fn _reaction_users(&self, - MessageId(id): MessageId, - reaction_type: ReactionType, - limit: Option<u8>, - after: Option<UserId>) - -> Result<Vec<User>> { let limit = limit.map_or(50, |x| if x > 100 { 100 } else { x }); http::get_reaction_users( self.0, - id, - &reaction_type, + message_id.into().0, + &reaction_type.into(), limit, - after.map(|u| u.0), + after.map(|u| u.into().0), ) } @@ -541,10 +504,6 @@ impl ChannelId { http::unpin_message(self.0, message_id.into().0) } - fn _unpin(&self, MessageId(id): MessageId) -> Result<()> { - http::unpin_message(self.0, id) - } - /// Retrieves the channel's webhooks. /// /// **Note**: Requires the [Manage Webhooks] permission. diff --git a/src/model/channel/group.rs b/src/model/channel/group.rs index dfccca3..418ce3a 100644 --- a/src/model/channel/group.rs +++ b/src/model/channel/group.rs @@ -49,10 +49,8 @@ impl Group { /// /// [`http::add_group_recipient`]: ../http/fn.add_group_recipient.html pub fn add_recipient<U: Into<UserId>>(&self, user: U) -> Result<()> { - self._add_recipient(user.into()) - } + let user = user.into(); - fn _add_recipient(&self, user: UserId) -> Result<()> { // If the group already contains the recipient, do nothing. if self.recipients.contains_key(&user) { return Ok(()); @@ -255,10 +253,8 @@ impl Group { /// /// **Note**: This is only available to the group owner. pub fn remove_recipient<U: Into<UserId>>(&self, user: U) -> Result<()> { - self._remove_recipient(user.into()) - } + let user = user.into(); - fn _remove_recipient(&self, user: UserId) -> Result<()> { // If the group does not contain the recipient already, do nothing. if !self.recipients.contains_key(&user) { return Ok(()); diff --git a/src/model/channel/message.rs b/src/model/channel/message.rs index 52f5be5..55f61ba 100644 --- a/src/model/channel/message.rs +++ b/src/model/channel/message.rs @@ -419,10 +419,6 @@ impl Message { /// [Add Reactions]: permissions/constant.ADD_REACTIONS.html /// [permissions]: permissions pub fn react<R: Into<ReactionType>>(&self, reaction_type: R) -> Result<()> { - self._react(reaction_type.into()) - } - - fn _react(&self, reaction_type: ReactionType) -> Result<()> { #[cfg(feature = "cache")] { let req = Permissions::ADD_REACTIONS; @@ -432,7 +428,7 @@ impl Message { } } - http::create_reaction(self.channel_id.0, self.id.0, &reaction_type) + http::create_reaction(self.channel_id.0, self.id.0, &reaction_type.into()) } /// Replies to the user, mentioning them prior to the content in the form diff --git a/src/model/channel/reaction.rs b/src/model/channel/reaction.rs index 976ea3d..8edc2e9 100644 --- a/src/model/channel/reaction.rs +++ b/src/model/channel/reaction.rs @@ -106,20 +106,12 @@ impl Reaction { after: Option<U>) -> Result<Vec<User>> where R: Into<ReactionType>, U: Into<UserId> { - self._users(reaction_type.into(), limit, after.map(|u| u.into())) - } - - fn _users(&self, - reaction_type: ReactionType, - limit: Option<u8>, - after: Option<UserId>) - -> Result<Vec<User>> { http::get_reaction_users( self.channel_id.0, self.message_id.0, - &reaction_type, + &reaction_type.into(), limit.unwrap_or(50), - after.map(|u| u.0), + after.map(|u| u.into().0), ) } } diff --git a/src/model/guild/guild_id.rs b/src/model/guild/guild_id.rs index bc50e16..4b9a713 100644 --- a/src/model/guild/guild_id.rs +++ b/src/model/guild/guild_id.rs @@ -49,10 +49,6 @@ impl GuildId { /// [`User`]: struct.User.html /// [Ban Members]: permissions/constant.BAN_MEMBERS.html pub fn ban<U: Into<UserId>, BO: BanOptions>(&self, user: U, ban_options: BO) -> Result<()> { - self._ban(user.into(), ban_options) - } - - fn _ban<BO: BanOptions>(&self, UserId(id): UserId, ban_options: BO) -> Result<()> { let dmd = ban_options.dmd(); if dmd > 7 { return Err(Error::Model(ModelError::DeleteMessageDaysAmount(dmd))); @@ -64,7 +60,7 @@ impl GuildId { return Err(Error::ExceededLimit(reason.to_string(), 512)); } - http::ban_user(self.0, id, dmd, &reason) + http::ban_user(self.0, user.into().0, dmd, &*reason) } /// Gets a list of the guild's bans. @@ -153,16 +149,13 @@ impl GuildId { /// [Manage Guild]: permissions/constant.MANAGE_GUILD.html pub fn create_integration<I>(&self, integration_id: I, kind: &str) -> Result<()> where I: Into<IntegrationId> { - self._create_integration(integration_id.into(), kind) - } - - fn _create_integration(&self, IntegrationId(id): IntegrationId, kind: &str) -> Result<()> { + let integration_id = integration_id.into(); let map = json!({ - "id": id, + "id": integration_id.0, "type": kind, }); - http::create_guild_integration(self.0, id, &map) + http::create_guild_integration(self.0, integration_id.0, &map) } /// Creates a new role in the guild with the data set, if any. @@ -197,11 +190,7 @@ impl GuildId { /// [Manage Emojis]: permissions/constant.MANAGE_EMOJIS.html #[inline] pub fn delete_emoji<E: Into<EmojiId>>(&self, emoji_id: E) -> Result<()> { - self._delete_emoji(emoji_id.into()) - } - - fn _delete_emoji(&self, EmojiId(id): EmojiId) -> Result<()> { - http::delete_emoji(self.0, id) + http::delete_emoji(self.0, emoji_id.into().0) } /// Deletes an integration by Id from the guild. @@ -211,11 +200,7 @@ impl GuildId { /// [Manage Guild]: permissions/constant.MANAGE_GUILD.html #[inline] pub fn delete_integration<I: Into<IntegrationId>>(&self, integration_id: I) -> Result<()> { - self._delete_integration(integration_id.into()) - } - - fn _delete_integration(&self, IntegrationId(id): IntegrationId) -> Result<()> { - http::delete_guild_integration(self.0, id) + http::delete_guild_integration(self.0, integration_id.into().0) } /// Deletes a [`Role`] by Id from the guild. @@ -230,11 +215,7 @@ impl GuildId { /// [Manage Roles]: permissions/constant.MANAGE_ROLES.html #[inline] pub fn delete_role<R: Into<RoleId>>(&self, role_id: R) -> Result<()> { - self._delete_role(role_id.into()) - } - - fn _delete_role(&self, RoleId(id): RoleId) -> Result<()> { - http::delete_role(self.0, id) + http::delete_role(self.0, role_id.into().0) } /// Edits the current guild with new data where specified. @@ -262,15 +243,11 @@ impl GuildId { /// [`Emoji::edit`]: struct.Emoji.html#method.edit /// [Manage Emojis]: permissions/constant.MANAGE_EMOJIS.html pub fn edit_emoji<E: Into<EmojiId>>(&self, emoji_id: E, name: &str) -> Result<Emoji> { - self._edit_emoji(emoji_id.into(), name) - } - - fn _edit_emoji(&self, EmojiId(id): EmojiId, name: &str) -> Result<Emoji> { let map = json!({ "name": name, }); - http::edit_emoji(self.0, id, &map) + http::edit_emoji(self.0, emoji_id.into().0, &map) } /// Edits the properties of member of the guild, such as muting or @@ -289,12 +266,7 @@ impl GuildId { #[inline] pub fn edit_member<F, U>(&self, user_id: U, f: F) -> Result<()> where F: FnOnce(EditMember) -> EditMember, U: Into<UserId> { - self._edit_member(user_id.into(), f) - } - - fn _edit_member<F>(&self, UserId(id): UserId, f: F) -> Result<()> - where F: FnOnce(EditMember) -> EditMember { - http::edit_member(self.0, id, &f(EditMember::default()).0) + http::edit_member(self.0, user_id.into().0, &f(EditMember::default()).0) } /// Edits the current user's nickname for the guild. @@ -328,12 +300,7 @@ impl GuildId { #[inline] pub fn edit_role<F, R>(&self, role_id: R, f: F) -> Result<Role> where F: FnOnce(EditRole) -> EditRole, R: Into<RoleId> { - self._edit_role(role_id.into(), f) - } - - fn _edit_role<F>(&self, RoleId(id): RoleId, f: F) -> Result<Role> - where F: FnOnce(EditRole) -> EditRole { - http::edit_role(self.0, id, &f(EditRole::default()).0) + http::edit_role(self.0, role_id.into().0, &f(EditRole::default()).0) } /// Search the cache for the guild. @@ -369,11 +336,7 @@ impl GuildId { /// [Kick Members]: permissions/constant.KICK_MEMBERS.html #[inline] pub fn kick<U: Into<UserId>>(&self, user_id: U) -> Result<()> { - self._kick(user_id.into()) - } - - fn _kick(&self, UserId(id): UserId) -> Result<()> { - http::kick_member(self.0, id) + http::kick_member(self.0, user_id.into().0) } /// Leaves the guild. @@ -386,11 +349,7 @@ impl GuildId { /// [`Member`]: struct.Member.html #[inline] pub fn member<U: Into<UserId>>(&self, user_id: U) -> Result<Member> { - self._member(user_id.into()) - } - - fn _member(&self, UserId(id): UserId) -> Result<Member> { - http::get_member(self.0, id) + http::get_member(self.0, user_id.into().0) } /// Gets a list of the guild's members. @@ -403,11 +362,7 @@ impl GuildId { #[inline] pub fn members<U>(&self, limit: Option<u64>, after: Option<U>) -> Result<Vec<Member>> where U: Into<UserId> { - self._members(limit, after.map(|x| x.into())) - } - - fn _members(&self, limit: Option<u64>, after: Option<UserId>) -> Result<Vec<Member>> { - http::get_guild_members(self.0, limit, after.map(|x| x.0)) + http::get_guild_members(self.0, limit, after.map(|x| x.into().0)) } /// Moves a member to a specific voice channel. @@ -417,17 +372,13 @@ impl GuildId { /// [Move Members]: permissions/constant.MOVE_MEMBERS.html pub fn move_member<C, U>(&self, user_id: U, channel_id: C) -> Result<()> where C: Into<ChannelId>, U: Into<UserId> { - self._move_member(user_id.into(), channel_id.into()) - } - - fn _move_member(&self, UserId(uid): UserId, ChannelId(cid): ChannelId) -> Result<()> { let mut map = Map::new(); map.insert( "channel_id".to_string(), - Value::Number(Number::from(cid)), + Value::Number(Number::from(channel_id.into().0)), ); - http::edit_member(self.0, uid, &map) + http::edit_member(self.0, user_id.into().0, &map) } /// Gets the number of [`Member`]s that would be pruned with the given @@ -491,11 +442,7 @@ impl GuildId { /// [Manage Guild]: permissions/constant.MANAGE_GUILD.html #[inline] pub fn start_integration_sync<I: Into<IntegrationId>>(&self, integration_id: I) -> Result<()> { - self._start_integration_sync(integration_id.into()) - } - - fn _start_integration_sync(&self, IntegrationId(id): IntegrationId) -> Result<()> { - http::start_integration_sync(self.0, id) + http::start_integration_sync(self.0, integration_id.into().0) } /// Starts a prune of [`Member`]s. @@ -524,11 +471,7 @@ impl GuildId { /// [Ban Members]: permissions/constant.BAN_MEMBERS.html #[inline] pub fn unban<U: Into<UserId>>(&self, user_id: U) -> Result<()> { - self._unban(user_id.into()) - } - - fn _unban(&self, UserId(id): UserId) -> Result<()> { - http::remove_ban(self.0, id) + http::remove_ban(self.0, user_id.into().0) } /// Retrieves the guild's webhooks. diff --git a/src/model/guild/member.rs b/src/model/guild/member.rs index 1b846ff..364b9f4 100644 --- a/src/model/guild/member.rs +++ b/src/model/guild/member.rs @@ -78,18 +78,15 @@ impl Member { /// [Manage Roles]: permissions/constant.MANAGE_ROLES.html #[cfg(feature = "cache")] pub fn add_role<R: Into<RoleId>>(&mut self, role_id: R) -> Result<()> { - self._add_role(role_id.into()) - } + let role_id = role_id.into(); - #[cfg(feature = "cache")] - fn _add_role(&mut self, id: RoleId) -> Result<()> { - if self.roles.contains(&id) { + if self.roles.contains(&role_id) { return Ok(()); } - match http::add_member_role(self.guild_id.0, self.user.read().unwrap().id.0, id.0) { + match http::add_member_role(self.guild_id.0, self.user.read().unwrap().id.0, role_id.0) { Ok(()) => { - self.roles.push(id); + self.roles.push(role_id); Ok(()) }, @@ -337,18 +334,15 @@ impl Member { /// [Manage Roles]: permissions/constant.MANAGE_ROLES.html #[cfg(feature = "cache")] pub fn remove_role<R: Into<RoleId>>(&mut self, role_id: R) -> Result<()> { - self._remove_role(role_id.into()) - } + let role_id = role_id.into(); - #[cfg(feature = "cache")] - fn _remove_role(&mut self, id: RoleId) -> Result<()> { - if !self.roles.contains(&id) { + if !self.roles.contains(&role_id) { return Ok(()); } - match http::remove_member_role(self.guild_id.0, self.user.read().unwrap().id.0, id.0) { + match http::remove_member_role(self.guild_id.0, self.user.read().unwrap().id.0, role_id.0) { Ok(()) => { - self.roles.retain(|r| r.0 != id.0); + self.roles.retain(|r| r.0 != role_id.0); Ok(()) }, diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs index da42a71..eef9d73 100644 --- a/src/model/guild/mod.rs +++ b/src/model/guild/mod.rs @@ -202,10 +202,6 @@ impl Guild { /// [`User`]: struct.User.html /// [Ban Members]: permissions/constant.BAN_MEMBERS.html pub fn ban<U: Into<UserId>, BO: BanOptions>(&self, user: U, options: BO) -> Result<()> { - self._ban(user.into(), options) - } - - fn _ban<BO: BanOptions>(&self, user: UserId, options: BO) -> Result<()> { #[cfg(feature = "cache")] { let req = Permissions::BAN_MEMBERS; @@ -601,9 +597,7 @@ impl Guild { /// /// Requires that the current user be in the guild. #[inline] - pub fn get<G: Into<GuildId>>(guild_id: G) -> Result<PartialGuild> { Self::_get(guild_id.into()) } - - fn _get(guild_id: GuildId) -> Result<PartialGuild> { guild_id.get() } + pub fn get<G: Into<GuildId>>(guild_id: G) -> Result<PartialGuild> { guild_id.into().get() } /// Returns the formatted URL of the guild's icon, if one exists. pub fn icon_url(&self) -> Option<String> { @@ -760,15 +754,15 @@ impl Guild { /// [`User`]: struct.User.html pub fn permissions_for<C, U>(&self, channel_id: C, user_id: U) -> Permissions where C: Into<ChannelId>, U: Into<UserId> { - self._permissions_for(channel_id.into(), user_id.into()) - } + let user_id = user_id.into(); - fn _permissions_for(&self, ChannelId(cid): ChannelId, UserId(uid): UserId) -> Permissions { // The owner has all permissions in all cases. - if self.owner_id == uid { + if user_id == self.owner_id { return Permissions::all(); } + let channel_id = channel_id.into(); + // Start by retrieving the @everyone role's permissions. let everyone = match self.roles.get(&RoleId(self.id.0)) { Some(everyone) => everyone, @@ -786,7 +780,7 @@ impl Guild { // Create a base set of permissions, starting with `@everyone`s. let mut permissions = everyone.permissions; - let member = match self.members.get(&UserId(uid)) { + let member = match self.members.get(&user_id) { Some(member) => member, None => return everyone.permissions, }; @@ -809,7 +803,7 @@ impl Guild { return Permissions::all(); } - if let Some(channel) = self.channels.get(&ChannelId(cid)) { + if let Some(channel) = self.channels.get(&channel_id) { let channel = channel.read().unwrap(); // If this is a text channel, then throw out voice permissions. @@ -842,7 +836,7 @@ impl Guild { // Member for overwrite in &channel.permission_overwrites { - if PermissionOverwriteType::Member(UserId(uid)) != overwrite.kind { + if PermissionOverwriteType::Member(user_id) != overwrite.kind { continue; } @@ -852,12 +846,12 @@ impl Guild { warn!( "(╯°□°)╯︵ ┻━┻ Guild {} does not contain channel {}", self.id, - cid + channel_id ); } // The default channel is always readable. - if cid == self.id.0 { + if channel_id.0 == self.id.0 { permissions |= Permissions::READ_MESSAGES; } @@ -1010,10 +1004,6 @@ impl Guild { /// [`User`]: struct.User.html /// [Ban Members]: permissions/constant.BAN_MEMBERS.html pub fn unban<U: Into<UserId>>(&self, user_id: U) -> Result<()> { - self._unban(user_id.into()) - } - - fn _unban(&self, user_id: UserId) -> Result<()> { #[cfg(feature = "cache")] { let req = Permissions::BAN_MEMBERS; diff --git a/src/model/invite.rs b/src/model/invite.rs index 9a836be..b4f326c 100644 --- a/src/model/invite.rs +++ b/src/model/invite.rs @@ -62,11 +62,8 @@ impl Invite { /// [permission]: permissions/index.html pub fn create<C, F>(channel_id: C, f: F) -> Result<RichInvite> where C: Into<ChannelId>, F: FnOnce(CreateInvite) -> CreateInvite { - Self::_create(channel_id.into(), f) - } + let channel_id = channel_id.into(); - fn _create<F>(channel_id: ChannelId, f: F) -> Result<RichInvite> - where F: FnOnce(CreateInvite) -> CreateInvite { #[cfg(feature = "cache")] { let req = Permissions::CREATE_INVITE; diff --git a/src/model/user.rs b/src/model/user.rs index c3c3c0d..3ae33aa 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -573,19 +573,17 @@ impl User { // no-cache would warn on guild_id. pub fn has_role<G, R>(&self, guild: G, role: R) -> bool where G: Into<GuildContainer>, R: Into<RoleId> { - self._has_role(guild.into(), role.into()) - } + let role_id = role.into(); - fn _has_role(&self, guild: GuildContainer, role: RoleId) -> bool { - match guild { - GuildContainer::Guild(guild) => guild.roles.contains_key(&role), + match guild.into() { + GuildContainer::Guild(guild) => guild.roles.contains_key(&role_id), GuildContainer::Id(_guild_id) => { feature_cache! {{ CACHE.read() .unwrap() .guilds .get(&_guild_id) - .map(|g| g.read().unwrap().roles.contains_key(&role)) + .map(|g| g.read().unwrap().roles.contains_key(&role_id)) .unwrap_or(false) } else { true diff --git a/src/utils/message_builder.rs b/src/utils/message_builder.rs index e1ba328..f58c0b3 100644 --- a/src/utils/message_builder.rs +++ b/src/utils/message_builder.rs @@ -122,12 +122,8 @@ impl MessageBuilder { /// [`ChannelId`]: ../model/struct.ChannelId.html /// [`GuildChannel`]: ../model/struct.GuildChannel.html /// [Display implementation]: ../model/struct.ChannelId.html#method.fmt-1 - pub fn channel<C: Into<ChannelId>>(self, channel: C) -> Self { - self._channel(channel.into()) - } - - fn _channel(mut self, channel: ChannelId) -> Self { - let _ = write!(self.0, "{}", channel.mention()); + pub fn channel<C: Into<ChannelId>>(mut self, channel: C) -> Self { + let _ = write!(self.0, "{}", channel.into().mention()); self } @@ -705,12 +701,8 @@ impl MessageBuilder { /// [`Role`]: ../model/struct.Role.html /// [`RoleId`]: ../model/struct.RoleId.html /// [Display implementation]: ../model/struct.RoleId.html#method.fmt-1 - pub fn role<R: Into<RoleId>>(self, role: R) -> Self { - self._role(role.into()) - } - - fn _role(mut self, role: RoleId) -> Self { - let _ = write!(self.0, "{}", role.mention()); + pub fn role<R: Into<RoleId>>(mut self, role: R) -> Self { + let _ = write!(self.0, "{}", role.into().mention()); self } @@ -726,12 +718,8 @@ impl MessageBuilder { /// [`User`]: ../model/struct.User.html /// [`UserId`]: ../model/struct.UserId.html /// [Display implementation]: ../model/struct.UserId.html#method.fmt-1 - pub fn user<U: Into<UserId>>(self, user: U) -> Self { - self._user(user.into()) - } - - fn _user(mut self, user: UserId) -> Self { - let _ = write!(self.0, "{}", user.mention()); + pub fn user<U: Into<UserId>>(mut self, user: U) -> Self { + let _ = write!(self.0, "{}", user.into().mention()); self } diff --git a/src/voice/manager.rs b/src/voice/manager.rs index 5aa392f..34d2a40 100644 --- a/src/voice/manager.rs +++ b/src/voice/manager.rs @@ -38,11 +38,7 @@ impl Manager { /// Retrieves a mutable handler for the given target, if one exists. pub fn get<G: Into<GuildId>>(&mut self, guild_id: G) -> Option<&mut Handler> { - self._get(guild_id.into()) - } - - fn _get(&mut self, guild_id: GuildId) -> Option<&mut Handler> { - self.handlers.get_mut(&guild_id) + self.handlers.get_mut(&guild_id.into()) } /// Connects to a target by retrieving its relevant [`Handler`] and @@ -69,10 +65,9 @@ impl Manager { #[allow(map_entry)] pub fn join<C, G>(&mut self, guild_id: G, channel_id: C) -> &mut Handler where C: Into<ChannelId>, G: Into<GuildId> { - self._join(guild_id.into(), channel_id.into()) - } + let channel_id = channel_id.into(); + let guild_id = guild_id.into(); - fn _join(&mut self, guild_id: GuildId, channel_id: ChannelId) -> &mut Handler { { let mut found = false; @@ -109,11 +104,7 @@ impl Manager { /// [`get`]: #method.get /// [`leave`]: struct.Handler.html#method.leave pub fn leave<G: Into<GuildId>>(&mut self, guild_id: G) { - self._leave(guild_id.into()) - } - - fn _leave(&mut self, guild_id: GuildId) { - if let Some(handler) = self.handlers.get_mut(&guild_id) { + if let Some(handler) = self.handlers.get_mut(&guild_id.into()) { handler.leave(); } } |