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/model | |
| 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/model')
| -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 |
9 files changed, 55 insertions, 190 deletions
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 |