aboutsummaryrefslogtreecommitdiff
path: root/src/model/channel
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2018-07-04 21:28:22 -0700
committerZeyla Hellyer <[email protected]>2018-07-04 21:32:17 -0700
commit7b9764cf1097b0620d871fabe67b5593f0cd4a4a (patch)
tree5b9f3eac6e9c57ac255c73bd1eea07669838f32d /src/model/channel
parentFix dead doc-links and add missing ones. (#347) (diff)
downloadserenity-7b9764cf1097b0620d871fabe67b5593f0cd4a4a.tar.xz
serenity-7b9764cf1097b0620d871fabe67b5593f0cd4a4a.zip
Monomorphize all functions
This commit monomorphizes all functions, turning functions like: ```rust fn foo<T: Into<Bar>>(baz: T) { baz = baz.into(); // function here } ``` Into functions like: ```rust fn foo<T: Into<Bar>>(baz: T) { _foo(baz.into()) } fn _foo(baz: Bar) { // function here } ``` This avoids binary bloat and improves build times, by reducing the amount of code duplication.
Diffstat (limited to 'src/model/channel')
-rw-r--r--src/model/channel/channel_id.rs86
-rw-r--r--src/model/channel/embed.rs8
-rw-r--r--src/model/channel/group.rs10
-rw-r--r--src/model/channel/guild_channel.rs5
-rw-r--r--src/model/channel/message.rs17
-rw-r--r--src/model/channel/reaction.rs14
6 files changed, 119 insertions, 21 deletions
diff --git a/src/model/channel/channel_id.rs b/src/model/channel/channel_id.rs
index f939be8..e3034f7 100644
--- a/src/model/channel/channel_id.rs
+++ b/src/model/channel/channel_id.rs
@@ -88,7 +88,15 @@ impl ChannelId {
#[inline]
pub fn create_reaction<M, R>(&self, message_id: M, reaction_type: R) -> Result<()>
where M: Into<MessageId>, R: Into<ReactionType> {
- http::create_reaction(self.0, message_id.into().0, &reaction_type.into())
+ self._create_reaction(message_id.into(), &reaction_type.into())
+ }
+
+ fn _create_reaction(
+ &self,
+ message_id: MessageId,
+ reaction_type: &ReactionType,
+ ) -> Result<()> {
+ http::create_reaction(self.0, message_id.0, reaction_type)
}
/// Deletes this channel, returning the channel on a successful deletion.
@@ -107,7 +115,11 @@ impl ChannelId {
/// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html
#[inline]
pub fn delete_message<M: Into<MessageId>>(&self, message_id: M) -> Result<()> {
- http::delete_message(self.0, message_id.into().0)
+ self._delete_message(message_id.into())
+ }
+
+ fn _delete_message(&self, message_id: MessageId) -> Result<()> {
+ http::delete_message(self.0, message_id.0)
}
/// Deletes all messages by Ids from the given vector in the given channel.
@@ -133,6 +145,11 @@ impl ChannelId {
.into_iter()
.map(|message_id| message_id.as_ref().0)
.collect::<Vec<u64>>();
+
+ self._delete_messages(ids)
+ }
+
+ fn _delete_messages(&self, ids: Vec<u64>) -> Result<()> {
let len = ids.len();
if len == 0 || len > 100 {
@@ -168,17 +185,31 @@ impl ChannelId {
///
/// [`Reaction`]: struct.Reaction.html
/// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html
+ #[inline]
pub fn delete_reaction<M, R>(&self,
message_id: M,
user_id: Option<UserId>,
reaction_type: R)
-> Result<()>
where M: Into<MessageId>, R: Into<ReactionType> {
+ self._delete_reaction(
+ message_id.into(),
+ user_id.into(),
+ &reaction_type.into(),
+ )
+ }
+
+ fn _delete_reaction(
+ &self,
+ message_id: MessageId,
+ user_id: Option<UserId>,
+ reaction_type: &ReactionType,
+ ) -> Result<()> {
http::delete_reaction(
self.0,
- message_id.into().0,
+ message_id.0,
user_id.map(|uid| uid.0),
- &reaction_type.into(),
+ reaction_type,
)
}
@@ -229,8 +260,14 @@ impl ChannelId {
/// [`Message`]: struct.Message.html
/// [`the limit`]: ../builder/struct.EditMessage.html#method.content
#[cfg(feature = "utils")]
+ #[inline]
pub fn edit_message<F, M>(&self, message_id: M, f: F) -> Result<Message>
where F: FnOnce(EditMessage) -> EditMessage, M: Into<MessageId> {
+ self._edit_message(message_id.into(), f)
+ }
+
+ fn _edit_message<F>(&self, message_id: MessageId, f: F) -> Result<Message>
+ where F: FnOnce(EditMessage) -> EditMessage {
let msg = f(EditMessage::default());
if let Some(content) = msg.0.get(&"content") {
@@ -243,7 +280,7 @@ impl ChannelId {
let map = utils::vecmap_to_json_map(msg.0);
- http::edit_message(self.0, message_id.into().0, &Value::Object(map))
+ http::edit_message(self.0, message_id.0, &Value::Object(map))
}
/// Search the cache for the channel with the Id.
@@ -277,7 +314,11 @@ impl ChannelId {
/// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html
#[inline]
pub fn message<M: Into<MessageId>>(&self, message_id: M) -> Result<Message> {
- http::get_message(self.0, message_id.into().0)
+ self._message(message_id.into())
+ }
+
+ fn _message(&self, message_id: MessageId) -> Result<Message> {
+ http::get_message(self.0, message_id.0)
.map(|mut msg| {
msg.transform_content();
@@ -350,7 +391,11 @@ impl ChannelId {
/// [`Message`]: struct.Message.html
#[inline]
pub fn pin<M: Into<MessageId>>(&self, message_id: M) -> Result<()> {
- http::pin_message(self.0, message_id.into().0)
+ self._pin(message_id.into())
+ }
+
+ fn _pin(&self, message_id: MessageId) -> Result<()> {
+ http::pin_message(self.0, message_id.0)
}
/// Gets the list of [`Message`]s which are pinned to the channel.
@@ -379,14 +424,29 @@ impl ChannelId {
) -> Result<Vec<User>> where M: Into<MessageId>,
R: Into<ReactionType>,
U: Into<Option<UserId>> {
+ self._reaction_users(
+ message_id.into(),
+ &reaction_type.into(),
+ limit,
+ after.into(),
+ )
+ }
+
+ fn _reaction_users(
+ &self,
+ message_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,
- message_id.into().0,
- &reaction_type.into(),
+ message_id.0,
+ reaction_type,
limit,
- after.into().map(|x| x.0),
+ after.map(|x| x.0),
)
}
@@ -529,7 +589,11 @@ impl ChannelId {
/// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html
#[inline]
pub fn unpin<M: Into<MessageId>>(&self, message_id: M) -> Result<()> {
- http::unpin_message(self.0, message_id.into().0)
+ self._unpin(message_id.into())
+ }
+
+ fn _unpin(&self, message_id: MessageId) -> Result<()> {
+ http::unpin_message(self.0, message_id.0)
}
/// Retrieves the channel's webhooks.
diff --git a/src/model/channel/embed.rs b/src/model/channel/embed.rs
index 8837a8d..bc2d0da 100644
--- a/src/model/channel/embed.rs
+++ b/src/model/channel/embed.rs
@@ -134,9 +134,13 @@ impl EmbedField {
/// [`value`]: #structfield.value
pub fn new<T, U>(name: T, value: U, inline: bool) -> Self
where T: Into<String>, U: Into<String> {
+ Self::_new(name.into(), value.into(), inline)
+ }
+
+ fn _new(name: String, value: String, inline: bool) -> Self {
Self {
- name: name.into(),
- value: value.into(),
+ name: name,
+ value: value,
inline,
}
}
diff --git a/src/model/channel/group.rs b/src/model/channel/group.rs
index 2fc062b..4baa654 100644
--- a/src/model/channel/group.rs
+++ b/src/model/channel/group.rs
@@ -53,9 +53,12 @@ impl Group {
/// user.
///
/// [`http::add_group_recipient`]: ../http/fn.add_group_recipient.html
+ #[inline]
pub fn add_recipient<U: Into<UserId>>(&self, user: U) -> Result<()> {
- let user = user.into();
+ self._add_recipient(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(());
@@ -261,9 +264,12 @@ impl Group {
/// the group, then nothing is done.
///
/// **Note**: This is only available to the group owner.
+ #[inline]
pub fn remove_recipient<U: Into<UserId>>(&self, user: U) -> Result<()> {
- let user = user.into();
+ self._remove_recipient(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/guild_channel.rs b/src/model/channel/guild_channel.rs
index 533aaf2..2f54fa1 100644
--- a/src/model/channel/guild_channel.rs
+++ b/src/model/channel/guild_channel.rs
@@ -520,7 +520,12 @@ impl GuildChannel {
/// [Attach Files]: permissions/constant.ATTACH_FILES.html
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
#[cfg(feature = "cache")]
+ #[inline]
pub fn permissions_for<U: Into<UserId>>(&self, user_id: U) -> Result<Permissions> {
+ self._permissions_for(user_id.into())
+ }
+
+ fn _permissions_for(&self, user_id: UserId) -> Result<Permissions> {
self.guild()
.ok_or_else(|| Error::Model(ModelError::GuildNotFound))
.map(|g| g.read().permissions_in(self.id, user_id))
diff --git a/src/model/channel/message.rs b/src/model/channel/message.rs
index 65cecd6..be17772 100644
--- a/src/model/channel/message.rs
+++ b/src/model/channel/message.rs
@@ -32,7 +32,7 @@ pub struct Message {
pub channel_id: ChannelId,
/// The Id of the [`Guild`] that the message was sent in. This value will
/// only be present if this message was received over the gateway.
- ///
+ ///
/// [`Guild`]: ../guild/struct.Guild.html
pub guild_id: Option<GuildId>,
/// The content of the message.
@@ -434,7 +434,12 @@ impl Message {
/// [`Emoji`]: struct.Emoji.html
/// [Add Reactions]: permissions/constant.ADD_REACTIONS.html
/// [permissions]: permissions
+ #[inline]
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;
@@ -444,7 +449,7 @@ impl Message {
}
}
- http::create_reaction(self.channel_id.0, self.id.0, &reaction_type.into())
+ http::create_reaction(self.channel_id.0, self.id.0, reaction_type)
}
/// Replies to the user, mentioning them prior to the content in the form
@@ -498,9 +503,13 @@ impl Message {
/// Checks whether the message mentions passed [`UserId`].
///
/// [`UserId`]: ../../model/id/struct.UserId.html
+ #[inline]
pub fn mentions_user_id<I: Into<UserId>>(&self, id: I) -> bool {
- let user_id_to_find = id.into();
- self.mentions.iter().any(|mentioned_user| mentioned_user.id.0 == user_id_to_find.0)
+ self._mentions_user_id(id.into())
+ }
+
+ fn _mentions_user_id(&self, id: UserId) -> bool {
+ self.mentions.iter().any(|mentioned_user| mentioned_user.id.0 == id.0)
}
/// Checks whether the message mentions passed [`User`].
diff --git a/src/model/channel/reaction.rs b/src/model/channel/reaction.rs
index 88f687f..0f65e8b 100644
--- a/src/model/channel/reaction.rs
+++ b/src/model/channel/reaction.rs
@@ -151,18 +151,28 @@ impl Reaction {
/// [`User`]: struct.User.html
/// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html
/// [permissions]: permissions
+ #[inline]
pub fn users<R, U>(&self,
reaction_type: R,
limit: Option<u8>,
after: Option<U>)
-> Result<Vec<User>>
where R: Into<ReactionType>, U: Into<UserId> {
+ self._users(&reaction_type.into(), limit, after.map(Into::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.into(),
+ reaction_type,
limit.unwrap_or(50),
- after.map(|u| u.into().0),
+ after.map(|u| u.0),
)
}
}