aboutsummaryrefslogtreecommitdiff
path: root/src/builder
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/builder
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/builder')
-rw-r--r--src/builder/create_embed.rs81
-rw-r--r--src/builder/create_message.rs18
-rw-r--r--src/builder/edit_channel.rs13
-rw-r--r--src/builder/edit_guild.rs26
-rw-r--r--src/builder/edit_member.rs19
-rw-r--r--src/builder/edit_message.rs7
-rw-r--r--src/builder/get_messages.rs27
7 files changed, 144 insertions, 47 deletions
diff --git a/src/builder/create_embed.rs b/src/builder/create_embed.rs
index c3c4cb0..48ea19d 100644
--- a/src/builder/create_embed.rs
+++ b/src/builder/create_embed.rs
@@ -65,14 +65,20 @@ impl CreateEmbed {
/// [`colour`]: #method.colour
#[cfg(feature = "utils")]
#[inline]
- pub fn color<C: Into<Colour>>(self, colour: C) -> Self { self.colour(colour.into()) }
+ pub fn color<C: Into<Colour>>(self, colour: C) -> Self { self.colour(colour) }
/// 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 {
+ #[inline]
+ pub fn colour<C: Into<Colour>>(self, colour: C) -> Self {
+ self._colour(colour.into())
+ }
+
+ #[cfg(feature = "utils")]
+ fn _colour(mut self, colour: Colour) -> Self {
self.0.insert(
"color",
- Value::Number(Number::from(u64::from(colour.into().0))),
+ Value::Number(Number::from(u64::from(colour.0))),
);
self
@@ -99,10 +105,15 @@ impl CreateEmbed {
/// Set the description of the embed.
///
/// **Note**: This can't be longer than 2048 characters.
- pub fn description<D: Display>(mut self, description: D) -> Self {
+ #[inline]
+ pub fn description<D: Display>(self, description: D) -> Self {
+ self._description(description.to_string())
+ }
+
+ fn _description(mut self, description: String) -> Self {
self.0.insert(
"description",
- Value::String(description.to_string()),
+ Value::String(description),
);
self
@@ -113,8 +124,13 @@ impl CreateEmbed {
///
/// **Note**: Maximum amount of characters you can put is 256 in a field
/// name and 1024 in a field value.
- pub fn field<T, U>(mut self, name: T, value: U, inline: bool) -> Self
+ #[inline]
+ pub fn field<T, U>(self, name: T, value: U, inline: bool) -> Self
where T: Display, U: Display {
+ self._field(name.to_string(), value.to_string(), inline)
+ }
+
+ fn _field(mut self, name: String, value: String, inline: bool) -> Self {
{
let entry = self.0
.entry("fields")
@@ -123,8 +139,8 @@ impl CreateEmbed {
if let Value::Array(ref mut inner) = *entry {
inner.push(json!({
"inline": inline,
- "name": name.to_string(),
- "value": value.to_string(),
+ "name": name,
+ "value": value,
}));
}
}
@@ -177,13 +193,21 @@ impl CreateEmbed {
/// Set the image associated with the embed. This only supports HTTP(S).
#[inline]
pub fn image<S: AsRef<str>>(self, url: S) -> Self {
- self.url_object("image", url.as_ref())
+ self._image(url.as_ref())
+ }
+
+ fn _image(self, url: &str) -> Self {
+ self.url_object("image", url)
}
/// Set the thumbnail of the embed. This only supports HTTP(S).
#[inline]
pub fn thumbnail<S: AsRef<str>>(self, url: S) -> Self {
- self.url_object("thumbnail", url.as_ref())
+ self._thumbnail(url.as_ref())
+ }
+
+ fn _thumbnail(self, url: &str) -> Self {
+ self.url_object("thumbnail", url)
}
/// Set the timestamp.
@@ -272,25 +296,37 @@ impl CreateEmbed {
///
/// client.start().unwrap();
/// ```
- pub fn timestamp<T: Into<Timestamp>>(mut self, timestamp: T) -> Self {
- self.0
- .insert("timestamp", Value::String(timestamp.into().ts));
+ #[inline]
+ pub fn timestamp<T: Into<Timestamp>>(self, timestamp: T) -> Self {
+ self._timestamp(timestamp.into())
+ }
+
+ fn _timestamp(mut self, timestamp: Timestamp) -> Self {
+ self.0.insert("timestamp", Value::String(timestamp.ts));
self
}
/// Set the title of the embed.
- pub fn title<D: Display>(mut self, title: D) -> Self {
- self.0
- .insert("title", Value::String(title.to_string()));
+ #[inline]
+ pub fn title<D: Display>(self, title: D) -> Self {
+ self._title(title.to_string())
+ }
+
+ fn _title(mut self, title: String) -> Self {
+ self.0.insert("title", Value::String(title));
self
}
/// Set the URL to direct to when clicking on the title.
- pub fn url<S: AsRef<str>>(mut self, url: S) -> Self {
- self.0
- .insert("url", Value::String(url.as_ref().to_string()));
+ #[inline]
+ pub fn url<S: AsRef<str>>(self, url: S) -> Self {
+ self._url(url.as_ref())
+ }
+
+ fn _url(mut self, url: &str) -> Self {
+ self.0.insert("url", Value::String(url.to_string()));
self
}
@@ -301,8 +337,13 @@ impl CreateEmbed {
/// with the provided filename. Or else this won't work.
///
/// [`ChannelId::send_files`]: ../model/id/struct.ChannelId.html#send_files
+ #[inline]
pub fn attachment<S: AsRef<str>>(self, filename: S) -> Self {
- self.image(&format!("attachment://{}", filename.as_ref()))
+ self._attachment(filename.as_ref())
+ }
+
+ fn _attachment(self, filename: &str) -> Self {
+ self.image(&format!("attachment://{}", filename))
}
}
diff --git a/src/builder/create_message.rs b/src/builder/create_message.rs
index df6f4d5..a5ede5a 100644
--- a/src/builder/create_message.rs
+++ b/src/builder/create_message.rs
@@ -46,8 +46,13 @@ impl CreateMessage {
/// Set the content of the message.
///
/// **Note**: Message contents must be under 2000 unicode code points.
- pub fn content<D: Display>(mut self, content: D) -> Self {
- self.0.insert("content", Value::String(content.to_string()));
+ #[inline]
+ pub fn content<D: Display>(self, content: D) -> Self {
+ self._content(content.to_string())
+ }
+
+ fn _content(mut self, content: String) -> Self {
+ self.0.insert("content", Value::String(content));
self
}
@@ -75,8 +80,13 @@ impl CreateMessage {
}
/// Adds a list of reactions to create after the message's sent.
- pub fn reactions<R: Into<ReactionType>, It: IntoIterator<Item=R>>(mut self, reactions: It) -> Self {
- self.1 = Some(reactions.into_iter().map(|r| r.into()).collect());
+ #[inline]
+ pub fn reactions<R: Into<ReactionType>, It: IntoIterator<Item=R>>(self, reactions: It) -> Self {
+ self._reactions(reactions.into_iter().map(Into::into).collect())
+ }
+
+ fn _reactions(mut self, reactions: Vec<ReactionType>) -> Self {
+ self.1 = Some(reactions);
self
}
diff --git a/src/builder/edit_channel.rs b/src/builder/edit_channel.rs
index b8d897b..e1b62a7 100644
--- a/src/builder/edit_channel.rs
+++ b/src/builder/edit_channel.rs
@@ -80,13 +80,16 @@ impl EditChannel {
///
/// [text]: ../model/channel/enum.ChannelType.html#variant.Text
/// [voice]: ../model/channel/enum.ChannelType.html#variant.Voice
- pub fn category<C>(mut self, category: C) -> Self
- where C: Into<Option<ChannelId>> {
- let parent_id = match category.into() {
+ #[inline]
+ pub fn category<C: Into<Option<ChannelId>>>(self, category: C) -> Self {
+ self._category(category.into())
+ }
+
+ fn _category(mut self, category: Option<ChannelId>) -> Self {
+ self.0.insert("parent_id", match category {
Some(c) => Value::Number(Number::from(c.0)),
None => Value::Null
- };
- self.0.insert("parent_id", parent_id);
+ });
self
}
diff --git a/src/builder/edit_guild.rs b/src/builder/edit_guild.rs
index c24b9b4..28abda7 100644
--- a/src/builder/edit_guild.rs
+++ b/src/builder/edit_guild.rs
@@ -23,11 +23,16 @@ impl EditGuild {
/// valid.
///
/// [`afk_timeout`]: #method.afk_timeout
- pub fn afk_channel<C: Into<ChannelId>>(mut self, channel: Option<C>) -> Self {
+ #[inline]
+ pub fn afk_channel<C: Into<ChannelId>>(self, channel: Option<C>) -> Self {
+ self._afk_channel(channel.map(Into::into))
+ }
+
+ fn _afk_channel(mut self, channel: Option<ChannelId>) -> Self {
self.0.insert(
"afk_channel_id",
match channel {
- Some(channel) => Value::Number(Number::from(channel.into().0)),
+ Some(channel) => Value::Number(Number::from(channel.0)),
None => Value::Null,
},
);
@@ -98,8 +103,13 @@ 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>>(mut self, user_id: U) -> Self {
- let id = Value::Number(Number::from(user_id.into().0));
+ #[inline]
+ pub fn owner<U: Into<UserId>>(self, user_id: U) -> Self {
+ self._owner(user_id.into())
+ }
+
+ fn _owner(mut self, user_id: UserId) -> Self {
+ let id = Value::Number(Number::from(user_id.0));
self.0.insert("owner_id", id);
self
@@ -180,10 +190,14 @@ impl EditGuild {
///
/// [`VerificationLevel`]: ../model/guild/enum.VerificationLevel.html
/// [`VerificationLevel::High`]: ../model/guild/enum.VerificationLevel.html#variant.High
- pub fn verification_level<V>(mut self, verification_level: V) -> Self
+ #[inline]
+ pub fn verification_level<V>(self, verification_level: V) -> Self
where V: Into<VerificationLevel> {
- let num = Value::Number(Number::from(verification_level.into().num()));
+ self._verification_level(verification_level.into())
+ }
+ fn _verification_level(mut self, verification_level: VerificationLevel) -> Self {
+ let num = Value::Number(Number::from(verification_level.num()));
self.0.insert("verification_level", num);
self
diff --git a/src/builder/edit_member.rs b/src/builder/edit_member.rs
index 19edb5e..c0791d6 100644
--- a/src/builder/edit_member.rs
+++ b/src/builder/edit_member.rs
@@ -50,13 +50,17 @@ impl EditMember {
/// Requires the [Manage Roles] permission to modify.
///
/// [Manage Roles]: ../model/permissions/constant.MANAGE_ROLES.html
- pub fn roles<T: AsRef<RoleId>, It: IntoIterator<Item=T>>(mut self, roles: It) -> Self {
- let role_ids = roles
+ pub fn roles<T: AsRef<RoleId>, It: IntoIterator<Item=T>>(self, roles: It) -> Self {
+ let roles = roles
.into_iter()
.map(|x| Value::Number(Number::from(x.as_ref().0)))
.collect();
- self.0.insert("roles", Value::Array(role_ids));
+ self._roles(roles)
+ }
+
+ fn _roles(mut self, roles: Vec<Value>) -> Self {
+ self.0.insert("roles", Value::Array(roles));
self
}
@@ -66,8 +70,13 @@ impl EditMember {
/// Requires the [Move Members] permission.
///
/// [Move Members]: ../model/permissions/constant.MOVE_MEMBERS.html
- pub fn voice_channel<C: Into<ChannelId>>(mut self, channel_id: C) -> Self {
- let num = Value::Number(Number::from(channel_id.into().0));
+ #[inline]
+ 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 {
+ let num = Value::Number(Number::from(channel_id.0));
self.0.insert("channel_id", num);
self
diff --git a/src/builder/edit_message.rs b/src/builder/edit_message.rs
index 29da46a..c62f072 100644
--- a/src/builder/edit_message.rs
+++ b/src/builder/edit_message.rs
@@ -26,7 +26,12 @@ impl EditMessage {
/// Set the content of the message.
///
/// **Note**: Message contents must be under 2000 unicode code points.
- pub fn content<D: Display>(mut self, content: D) -> Self {
+ #[inline]
+ pub fn content<D: Display>(self, content: D) -> Self {
+ self._content(content.to_string())
+ }
+
+ fn _content(mut self, content: String) -> Self {
self.0.insert("content", Value::String(content.to_string()));
self
diff --git a/src/builder/get_messages.rs b/src/builder/get_messages.rs
index f302ff0..2d7ee87 100644
--- a/src/builder/get_messages.rs
+++ b/src/builder/get_messages.rs
@@ -55,24 +55,39 @@ pub struct GetMessages(pub VecMap<&'static str, u64>);
impl GetMessages {
/// Indicates to retrieve the messages after a specific message, given by
/// its Id.
- pub fn after<M: Into<MessageId>>(mut self, message_id: M) -> Self {
- self.0.insert("after", message_id.into().0);
+ #[inline]
+ pub fn after<M: Into<MessageId>>(self, message_id: M) -> Self {
+ self._after(message_id.into())
+ }
+
+ fn _after(mut self, message_id: MessageId) -> Self {
+ self.0.insert("after", message_id.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>>(mut self, message_id: M) -> Self {
- self.0.insert("around", message_id.into().0);
+ #[inline]
+ pub fn around<M: Into<MessageId>>(self, message_id: M) -> Self {
+ self._around(message_id.into())
+ }
+
+ fn _around(mut self, message_id: MessageId) -> Self {
+ self.0.insert("around", message_id.0);
self
}
/// Indicates to retrieve the messages before a specific message, given by
/// its Id.
- pub fn before<M: Into<MessageId>>(mut self, message_id: M) -> Self {
- self.0.insert("before", message_id.into().0);
+ #[inline]
+ pub fn before<M: Into<MessageId>>(self, message_id: M) -> Self {
+ self._before(message_id.into())
+ }
+
+ fn _before(mut self, message_id: MessageId) -> Self {
+ self.0.insert("before", message_id.0);
self
}