aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--src/cache/mod.rs59
-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
-rw-r--r--src/model/guild/guild_id.rs129
-rw-r--r--src/model/guild/member.rs21
-rw-r--r--src/model/guild/mod.rs32
-rw-r--r--src/model/invite.rs5
-rw-r--r--src/model/user.rs8
-rw-r--r--src/utils/message_builder.rs18
-rw-r--r--src/utils/mod.rs5
-rw-r--r--src/voice/manager.rs36
-rw-r--r--src/voice/streamer.rs10
23 files changed, 527 insertions, 127 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
}
diff --git a/src/cache/mod.rs b/src/cache/mod.rs
index bee2b45..e0a5ee6 100644
--- a/src/cache/mod.rs
+++ b/src/cache/mod.rs
@@ -320,9 +320,12 @@ impl Cache {
/// [`private_channel`]: #method.private_channel
/// [`groups`]: #structfield.groups
/// [`private_channels`]: #structfield.private_channels
+ #[inline]
pub fn channel<C: Into<ChannelId>>(&self, id: C) -> Option<Channel> {
- let id = id.into();
+ self._channel(id.into())
+ }
+ fn _channel(&self, id: ChannelId) -> Option<Channel> {
if let Some(channel) = self.channels.get(&id) {
return Some(Channel::Guild(Arc::clone(channel)));
}
@@ -367,7 +370,11 @@ impl Cache {
/// ```
#[inline]
pub fn guild<G: Into<GuildId>>(&self, id: G) -> Option<Arc<RwLock<Guild>>> {
- self.guilds.get(&id.into()).cloned()
+ self._guild(id.into())
+ }
+
+ fn _guild(&self, id: GuildId) -> Option<Arc<RwLock<Guild>>> {
+ self.guilds.get(&id).cloned()
}
/// Retrieves a reference to a [`Guild`]'s channel. Unlike [`channel`],
@@ -424,7 +431,11 @@ impl Cache {
/// [`channel`]: #method.channel
#[inline]
pub fn guild_channel<C: Into<ChannelId>>(&self, id: C) -> Option<Arc<RwLock<GuildChannel>>> {
- self.channels.get(&id.into()).cloned()
+ self._guild_channel(id.into())
+ }
+
+ fn _guild_channel(&self, id: ChannelId) -> Option<Arc<RwLock<GuildChannel>>> {
+ self.channels.get(&id).cloned()
}
/// Retrieves a reference to a [`Group`] from the cache based on the given
@@ -458,7 +469,11 @@ impl Cache {
/// ```
#[inline]
pub fn group<C: Into<ChannelId>>(&self, id: C) -> Option<Arc<RwLock<Group>>> {
- self.groups.get(&id.into()).cloned()
+ self._group(id.into())
+ }
+
+ fn _group(&self, id: ChannelId) -> Option<Arc<RwLock<Group>>> {
+ self.groups.get(&id).cloned()
}
/// Retrieves a [`Guild`]'s member from the cache based on the guild's and
@@ -506,10 +521,15 @@ impl Cache {
/// [`Client::on_message`]: ../client/struct.Client.html#method.on_message
/// [`Guild`]: ../model/guild/struct.Guild.html
/// [`members`]: ../model/guild/struct.Guild.html#structfield.members
+ #[inline]
pub fn member<G, U>(&self, guild_id: G, user_id: U) -> Option<Member>
where G: Into<GuildId>, U: Into<UserId> {
- self.guilds.get(&guild_id.into()).and_then(|guild| {
- guild.read().members.get(&user_id.into()).cloned()
+ self._member(guild_id.into(), user_id.into())
+ }
+
+ fn _member(&self, guild_id: GuildId, user_id: UserId) -> Option<Member> {
+ self.guilds.get(&guild_id).and_then(|guild| {
+ guild.read().members.get(&user_id).cloned()
})
}
@@ -549,7 +569,11 @@ impl Cache {
pub fn private_channel<C: Into<ChannelId>>(&self,
channel_id: C)
-> Option<Arc<RwLock<PrivateChannel>>> {
- self.private_channels.get(&channel_id.into()).cloned()
+ self._private_channel(channel_id.into())
+ }
+
+ fn _private_channel(&self, channel_id: ChannelId) -> Option<Arc<RwLock<PrivateChannel>>> {
+ self.private_channels.get(&channel_id).cloned()
}
/// Retrieves a [`Guild`]'s role by their Ids.
@@ -580,11 +604,16 @@ impl Cache {
/// # try_main().unwrap();
/// # }
/// ```
+ #[inline]
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.into())
- .and_then(|g| g.read().roles.get(&role_id.into()).cloned())
+ .get(&guild_id)
+ .and_then(|g| g.read().roles.get(&role_id).cloned())
}
/// Retrieves a `User` from the cache's [`users`] map, if it exists.
@@ -617,14 +646,22 @@ impl Cache {
/// ```
#[inline]
pub fn user<U: Into<UserId>>(&self, user_id: U) -> Option<Arc<RwLock<User>>> {
- self.users.get(&user_id.into()).cloned()
+ self._user(user_id.into())
+ }
+
+ fn _user(&self, user_id: UserId) -> Option<Arc<RwLock<User>>> {
+ self.users.get(&user_id).cloned()
}
#[inline]
pub fn categories<C: Into<ChannelId>>(&self,
channel_id: C)
-> Option<Arc<RwLock<ChannelCategory>>> {
- self.categories.get(&channel_id.into()).cloned()
+ self._categories(channel_id.into())
+ }
+
+ fn _categories(&self, channel_id: ChannelId) -> Option<Arc<RwLock<ChannelCategory>>> {
+ self.categories.get(&channel_id).cloned()
}
#[cfg(feature = "client")]
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),
)
}
}
diff --git a/src/model/guild/guild_id.rs b/src/model/guild/guild_id.rs
index c07a40f..a209369 100644
--- a/src/model/guild/guild_id.rs
+++ b/src/model/guild/guild_id.rs
@@ -48,20 +48,24 @@ impl GuildId {
/// [`Guild::ban`]: struct.Guild.html#method.ban
/// [`User`]: struct.User.html
/// [Ban Members]: permissions/constant.BAN_MEMBERS.html
+ #[inline]
pub fn ban<U, BO>(&self, user: U, ban_options: &BO) -> Result<()>
where U: Into<UserId>, BO: BanOptions {
- let dmd = ban_options.dmd();
+ self._ban(user.into(), (ban_options.dmd(), ban_options.reason()))
+ }
+
+ fn _ban(&self, user: UserId, ban_options: (u8, &str)) -> Result<()> {
+ let (dmd, reason) = ban_options;
+
if dmd > 7 {
return Err(Error::Model(ModelError::DeleteMessageDaysAmount(dmd)));
}
- let reason = ban_options.reason();
-
if reason.len() > 512 {
return Err(Error::ExceededLimit(reason.to_string(), 512));
}
- http::ban_user(self.0, user.into().0, dmd, &*reason)
+ http::ban_user(self.0, user.0, dmd, reason)
}
/// Gets a list of the guild's bans.
@@ -113,12 +117,22 @@ impl GuildId {
/// [`GuildChannel`]: struct.GuildChannel.html
/// [`http::create_channel`]: ../http/fn.create_channel.html
/// [Manage Channels]: permissions/constant.MANAGE_CHANNELS.html
+ #[inline]
pub fn create_channel<C>(&self, name: &str, kind: ChannelType, category: C) -> Result<GuildChannel>
where C: Into<Option<ChannelId>> {
+ self._create_channel(name, kind, category.into())
+ }
+
+ fn _create_channel(
+ &self,
+ name: &str,
+ kind: ChannelType,
+ category: Option<ChannelId>,
+ ) -> Result<GuildChannel> {
let map = json!({
"name": name,
"type": kind as u8,
- "parent_id": category.into().map(|c| c.0)
+ "parent_id": category.map(|c| c.0)
});
http::create_channel(self.0, &map)
@@ -141,6 +155,7 @@ impl GuildId {
/// [`Guild::create_emoji`]: struct.Guild.html#method.create_emoji
/// [`utils::read_image`]: ../utils/fn.read_image.html
/// [Manage Emojis]: permissions/constant.MANAGE_EMOJIS.html
+ #[inline]
pub fn create_emoji(&self, name: &str, image: &str) -> Result<Emoji> {
let map = json!({
"name": name,
@@ -155,9 +170,17 @@ impl GuildId {
/// Requires the [Manage Guild] permission.
///
/// [Manage Guild]: permissions/constant.MANAGE_GUILD.html
+ #[inline]
pub fn create_integration<I>(&self, integration_id: I, kind: &str) -> Result<()>
where I: Into<IntegrationId> {
- let integration_id = integration_id.into();
+ self._create_integration(integration_id.into(), kind)
+ }
+
+ fn _create_integration(
+ &self,
+ integration_id: IntegrationId,
+ kind: &str,
+ ) -> Result<()> {
let map = json!({
"id": integration_id.0,
"type": kind,
@@ -206,7 +229,11 @@ impl GuildId {
/// [Manage Emojis]: permissions/constant.MANAGE_EMOJIS.html
#[inline]
pub fn delete_emoji<E: Into<EmojiId>>(&self, emoji_id: E) -> Result<()> {
- http::delete_emoji(self.0, emoji_id.into().0)
+ self._delete_emoji(emoji_id.into())
+ }
+
+ fn _delete_emoji(&self, emoji_id: EmojiId) -> Result<()> {
+ http::delete_emoji(self.0, emoji_id.0)
}
/// Deletes an integration by Id from the guild.
@@ -216,7 +243,11 @@ impl GuildId {
/// [Manage Guild]: permissions/constant.MANAGE_GUILD.html
#[inline]
pub fn delete_integration<I: Into<IntegrationId>>(&self, integration_id: I) -> Result<()> {
- http::delete_guild_integration(self.0, integration_id.into().0)
+ self._delete_integration(integration_id.into())
+ }
+
+ fn _delete_integration(&self, integration_id: IntegrationId) -> Result<()> {
+ http::delete_guild_integration(self.0, integration_id.0)
}
/// Deletes a [`Role`] by Id from the guild.
@@ -231,7 +262,11 @@ impl GuildId {
/// [Manage Roles]: permissions/constant.MANAGE_ROLES.html
#[inline]
pub fn delete_role<R: Into<RoleId>>(&self, role_id: R) -> Result<()> {
- http::delete_role(self.0, role_id.into().0)
+ self._delete_role(role_id.into())
+ }
+
+ fn _delete_role(&self, role_id: RoleId) -> Result<()> {
+ http::delete_role(self.0, role_id.0)
}
/// Edits the current guild with new data where specified.
@@ -260,12 +295,17 @@ impl GuildId {
/// [`Emoji`]: struct.Emoji.html
/// [`Emoji::edit`]: struct.Emoji.html#method.edit
/// [Manage Emojis]: permissions/constant.MANAGE_EMOJIS.html
+ #[inline]
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, emoji_id: EmojiId, name: &str) -> Result<Emoji> {
let map = json!({
"name": name,
});
- http::edit_emoji(self.0, emoji_id.into().0, &map)
+ http::edit_emoji(self.0, emoji_id.0, &map)
}
/// Edits the properties of member of the guild, such as muting or
@@ -284,9 +324,14 @@ 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, user_id: UserId, f: F) -> Result<()>
+ where F: FnOnce(EditMember) -> EditMember {
let map = utils::vecmap_to_json_map(f(EditMember::default()).0);
- http::edit_member(self.0, user_id.into().0, &map)
+ http::edit_member(self.0, user_id.0, &map)
}
/// Edits the current user's nickname for the guild.
@@ -320,9 +365,14 @@ 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, role_id: RoleId, f: F) -> Result<Role>
+ where F: FnOnce(EditRole) -> EditRole {
let map = utils::vecmap_to_json_map(f(EditRole::default()).0);
- http::edit_role(self.0, role_id.into().0, &map)
+ http::edit_role(self.0, role_id.0, &map)
}
/// Edits the order of [`Role`]s
@@ -342,7 +392,15 @@ impl GuildId {
#[inline]
pub fn edit_role_position<R>(&self, role_id: R, position: u64) -> Result<Vec<Role>>
where R: Into<RoleId> {
- http::edit_role_position(self.0, role_id.into().0, position)
+ self._edit_role_position(role_id.into(), position)
+ }
+
+ fn _edit_role_position(
+ &self,
+ role_id: RoleId,
+ position: u64,
+ ) -> Result<Vec<Role>> {
+ http::edit_role_position(self.0, role_id.0, position)
}
@@ -392,7 +450,11 @@ impl GuildId {
/// [`Member`]: struct.Member.html
#[inline]
pub fn member<U: Into<UserId>>(&self, user_id: U) -> Result<Member> {
- http::get_member(self.0, user_id.into().0)
+ self._member(user_id.into())
+ }
+
+ fn _member(&self, user_id: UserId) -> Result<Member> {
+ http::get_member(self.0, user_id.0)
}
/// Gets a list of the guild's members.
@@ -405,7 +467,11 @@ impl GuildId {
#[inline]
pub fn members<U>(&self, limit: Option<u64>, after: Option<U>) -> Result<Vec<Member>>
where U: Into<UserId> {
- http::get_guild_members(self.0, limit, after.map(|x| x.into().0))
+ self._members(limit, after.map(Into::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))
}
/// Moves a member to a specific voice channel.
@@ -413,15 +479,24 @@ impl GuildId {
/// Requires the [Move Members] permission.
///
/// [Move Members]: permissions/constant.MOVE_MEMBERS.html
+ #[inline]
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,
+ user_id: UserId,
+ channel_id: ChannelId,
+ ) -> Result<()> {
let mut map = Map::new();
map.insert(
"channel_id".to_string(),
- Value::Number(Number::from(channel_id.into().0)),
+ Value::Number(Number::from(channel_id.0)),
);
- http::edit_member(self.0, user_id.into().0, &map)
+ http::edit_member(self.0, user_id.0, &map)
}
/// Gets the number of [`Member`]s that would be pruned with the given
@@ -447,8 +522,13 @@ impl GuildId {
/// Although not required, you should specify all channels' positions,
/// regardless of whether they were updated. Otherwise, positioning can
/// sometimes get weird.
+ #[inline]
pub fn reorder_channels<It>(&self, channels: It) -> Result<()>
where It: IntoIterator<Item = (ChannelId, u64)> {
+ self._reorder_channels(channels.into_iter().collect())
+ }
+
+ fn _reorder_channels(&self, channels: Vec<(ChannelId, u64)>) -> Result<()> {
let items = channels.into_iter().map(|(id, pos)| json!({
"id": id,
"position": pos,
@@ -503,7 +583,14 @@ impl GuildId {
/// [Manage Guild]: permissions/constant.MANAGE_GUILD.html
#[inline]
pub fn start_integration_sync<I: Into<IntegrationId>>(&self, integration_id: I) -> Result<()> {
- http::start_integration_sync(self.0, integration_id.into().0)
+ self._start_integration_sync(integration_id.into())
+ }
+
+ fn _start_integration_sync(
+ &self,
+ integration_id: IntegrationId,
+ ) -> Result<()> {
+ http::start_integration_sync(self.0, integration_id.0)
}
/// Starts a prune of [`Member`]s.
@@ -532,7 +619,11 @@ impl GuildId {
/// [Ban Members]: permissions/constant.BAN_MEMBERS.html
#[inline]
pub fn unban<U: Into<UserId>>(&self, user_id: U) -> Result<()> {
- http::remove_ban(self.0, user_id.into().0)
+ self._unban(user_id.into())
+ }
+
+ fn _unban(&self, user_id: UserId) -> Result<()> {
+ http::remove_ban(self.0, user_id.0)
}
/// Retrieve's the guild's vanity URL.
diff --git a/src/model/guild/member.rs b/src/model/guild/member.rs
index c95c07f..8101700 100644
--- a/src/model/guild/member.rs
+++ b/src/model/guild/member.rs
@@ -85,9 +85,13 @@ impl Member {
/// [`Role`]: struct.Role.html
/// [Manage Roles]: permissions/constant.MANAGE_ROLES.html
#[cfg(feature = "cache")]
+ #[inline]
pub fn add_role<R: Into<RoleId>>(&mut self, role_id: R) -> Result<()> {
- let role_id = role_id.into();
+ self._add_role(role_id.into())
+ }
+ #[cfg(feature = "cache")]
+ fn _add_role(&mut self, role_id: RoleId) -> Result<()> {
if self.roles.contains(&role_id) {
return Ok(());
}
@@ -140,14 +144,17 @@ impl Member {
///
/// [Ban Members]: permissions/constant.BAN_MEMBERS.html
#[cfg(feature = "cache")]
+ #[inline]
pub fn ban<BO: BanOptions>(&self, ban_options: &BO) -> Result<()> {
- let dmd = ban_options.dmd();
+ self._ban(ban_options.dmd(), ban_options.reason())
+ }
+
+ #[cfg(feature = "cache")]
+ fn _ban(&self, dmd: u8, reason: &str) -> Result<()> {
if dmd > 7 {
return Err(Error::Model(ModelError::DeleteMessageDaysAmount(dmd)));
}
- let reason = ban_options.reason();
-
if reason.len() > 512 {
return Err(Error::ExceededLimit(reason.to_string(), 512));
}
@@ -368,9 +375,13 @@ impl Member {
/// [`Role`]: struct.Role.html
/// [Manage Roles]: permissions/constant.MANAGE_ROLES.html
#[cfg(feature = "cache")]
+ #[inline]
pub fn remove_role<R: Into<RoleId>>(&mut self, role_id: R) -> Result<()> {
- let role_id = role_id.into();
+ self._remove_role(role_id.into())
+ }
+ #[cfg(feature = "cache")]
+ fn _remove_role(&mut self, role_id: RoleId) -> Result<()> {
if !self.roles.contains(&role_id) {
return Ok(());
}
diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs
index 9e4d8ef..4fc7079 100644
--- a/src/model/guild/mod.rs
+++ b/src/model/guild/mod.rs
@@ -229,9 +229,12 @@ impl Guild {
/// [`Guild::ban`]: struct.Guild.html#method.ban
/// [`User`]: struct.User.html
/// [Ban Members]: permissions/constant.BAN_MEMBERS.html
+ #[inline]
pub fn ban<U: Into<UserId>, BO: BanOptions>(&self, user: U, options: &BO) -> Result<()> {
- let user = user.into();
+ self._ban(user.into(), options)
+ }
+ fn _ban<BO: BanOptions>(&self, user: UserId, options: &BO) -> Result<()> {
#[cfg(feature = "cache")]
{
let req = Permissions::BAN_MEMBERS;
@@ -669,11 +672,18 @@ impl Guild {
/// If both user IDs are the same, `None` is returned. If one of the users
/// is the guild owner, their ID is returned.
#[cfg(feature = "cache")]
+ #[inline]
pub fn greater_member_hierarchy<T, U>(&self, lhs_id: T, rhs_id: U)
-> Option<UserId> where T: Into<UserId>, U: Into<UserId> {
- let lhs_id = lhs_id.into();
- let rhs_id = rhs_id.into();
+ self._greater_member_hierarchy(lhs_id.into(), rhs_id.into())
+ }
+ #[cfg(feature = "cache")]
+ fn _greater_member_hierarchy(
+ &self,
+ lhs_id: UserId,
+ rhs_id: UserId,
+ ) -> Option<UserId> {
// Check that the IDs are the same. If they are, neither is greater.
if lhs_id == rhs_id {
return None;
@@ -1106,10 +1116,13 @@ impl Guild {
/// Calculate a [`Member`]'s permissions in the guild.
///
/// [`Member`]: struct.Member.html
+ #[inline]
pub fn member_permissions<U>(&self, user_id: U) -> Permissions
where U: Into<UserId> {
- let user_id = user_id.into();
+ self._member_permissions(user_id.into())
+ }
+ fn _member_permissions(&self, user_id: UserId) -> Permissions {
if user_id == self.owner_id {
return Permissions::all();
}
@@ -1179,17 +1192,22 @@ impl Guild {
/// Calculate a [`User`]'s permissions in a given channel in the guild.
///
/// [`User`]: struct.User.html
+ #[inline]
pub fn permissions_in<C, U>(&self, channel_id: C, user_id: U) -> Permissions
where C: Into<ChannelId>, U: Into<UserId> {
- let user_id = user_id.into();
+ self._permissions_in(channel_id.into(), user_id.into())
+ }
+ fn _permissions_in(
+ &self,
+ channel_id: ChannelId,
+ user_id: UserId,
+ ) -> Permissions {
// The owner has all permissions in all cases.
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,
diff --git a/src/model/invite.rs b/src/model/invite.rs
index b93b231..2bbd5d9 100644
--- a/src/model/invite.rs
+++ b/src/model/invite.rs
@@ -70,8 +70,11 @@ 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 {
- let channel_id = channel_id.into();
+ Self::_create(channel_id.into(), f)
+ }
+ 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 330f319..48891d3 100644
--- a/src/model/user.rs
+++ b/src/model/user.rs
@@ -580,10 +580,12 @@ 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> {
- let role_id = role.into();
+ self._has_role(guild.into(), role.into())
+ }
+ fn _has_role(&self, guild: GuildContainer, role: RoleId) -> bool {
match guild.into() {
- GuildContainer::Guild(guild) => guild.roles.contains_key(&role_id),
+ GuildContainer::Guild(guild) => guild.roles.contains_key(&role),
GuildContainer::Id(_guild_id) => {
feature_cache! {{
CACHE.read()
@@ -591,7 +593,7 @@ impl User {
.get(&_guild_id)
.map(|g| {
g.read().members.get(&self.id)
- .map(|m| m.roles.contains(&role_id))
+ .map(|m| m.roles.contains(&role))
.unwrap_or(false)
})
.unwrap_or(false)
diff --git a/src/utils/message_builder.rs b/src/utils/message_builder.rs
index 93c5489..15c0b07 100644
--- a/src/utils/message_builder.rs
+++ b/src/utils/message_builder.rs
@@ -129,8 +129,13 @@ impl MessageBuilder {
/// [`ChannelId`]: ../model/id/struct.ChannelId.html
/// [`GuildChannel`]: ../model/channel/struct.GuildChannel.html
/// [Display implementation]: ../model/id/struct.ChannelId.html#method.fmt-1
- pub fn channel<C: Into<ChannelId>>(mut self, channel: C) -> Self {
- let _ = write!(self.0, "{}", channel.into().mention());
+ #[inline]
+ 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());
self
}
@@ -198,8 +203,13 @@ impl MessageBuilder {
///
/// assert_eq!(message.push("ing").0, "testing");
/// ```
- pub fn push<D: I>(mut self, content: D) -> Self {
- self.0.push_str(&content.into().to_string());
+ #[inline]
+ pub fn push<D: I>(self, content: D) -> Self {
+ self._push(content.into().to_string())
+ }
+
+ fn _push(mut self, content: String) -> Self {
+ self.0.push_str(&content);
self
}
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index 544aef4..e20dd22 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -348,9 +348,12 @@ pub fn parse_emoji(mention: &str) -> Option<EmojiIdentifier> {
/// ```
///
/// [`EditProfile::avatar`]: ../builder/struct.EditProfile.html#method.avatar
+#[inline]
pub fn read_image<P: AsRef<Path>>(path: P) -> Result<String> {
- let path = path.as_ref();
+ _read_image(path.as_ref())
+}
+fn _read_image(path: &Path) -> Result<String> {
let mut v = Vec::default();
let mut f = File::open(path)?;
let _ = f.read_to_end(&mut v);
diff --git a/src/voice/manager.rs b/src/voice/manager.rs
index c3e3ba2..4d1a7c4 100644
--- a/src/voice/manager.rs
+++ b/src/voice/manager.rs
@@ -39,14 +39,24 @@ impl Manager {
}
/// Retrieves an immutable handler for the given target, if one exists.
+ #[inline]
pub fn get<G: Into<GuildId>>(&self, guild_id: G) -> Option<&Handler> {
- self.handlers.get(&guild_id.into())
+ self._get(guild_id.into())
+ }
+
+ fn _get(&self, guild_id: GuildId) -> Option<&Handler> {
+ self.handlers.get(&guild_id)
}
/// Retrieves a mutable handler for the given target, if one exists.
+ #[inline]
pub fn get_mut<G: Into<GuildId>>(&mut self, guild_id: G)
-> Option<&mut Handler> {
- self.handlers.get_mut(&guild_id.into())
+ self._get_mut(guild_id.into())
+ }
+
+ fn _get_mut(&mut self, guild_id: GuildId) -> Option<&mut Handler> {
+ self.handlers.get_mut(&guild_id)
}
/// Connects to a target by retrieving its relevant [`Handler`] and
@@ -71,11 +81,17 @@ impl Manager {
/// [`Handler`]: struct.Handler.html
/// [`get`]: #method.get
#[allow(map_entry)]
+ #[inline]
pub fn join<C, G>(&mut self, guild_id: G, channel_id: C) -> &mut Handler
where C: Into<ChannelId>, G: Into<GuildId> {
- let channel_id = channel_id.into();
- let guild_id = guild_id.into();
+ self._join(guild_id.into(), channel_id.into())
+ }
+ fn _join(
+ &mut self,
+ guild_id: GuildId,
+ channel_id: ChannelId,
+ ) -> &mut Handler {
{
let mut found = false;
@@ -111,8 +127,13 @@ impl Manager {
/// [`Handler`]: struct.Handler.html
/// [`get`]: #method.get
/// [`leave`]: struct.Handler.html#method.leave
+ #[inline]
pub fn leave<G: Into<GuildId>>(&mut self, guild_id: G) {
- if let Some(handler) = self.handlers.get_mut(&guild_id.into()) {
+ self._leave(guild_id.into())
+ }
+
+ fn _leave(&mut self, guild_id: GuildId) {
+ if let Some(handler) = self.handlers.get_mut(&guild_id) {
handler.leave();
}
}
@@ -123,9 +144,12 @@ impl Manager {
/// The handler is then dropped, removing settings for the target.
///
/// [`Handler`]: struct.Handler.html
+ #[inline]
pub fn remove<G: Into<GuildId>>(&mut self, guild_id: G) {
- let guild_id = guild_id.into();
+ self._remove(guild_id.into())
+ }
+ fn _remove(&mut self, guild_id: GuildId) {
self.leave(guild_id);
self.handlers.remove(&guild_id);
diff --git a/src/voice/streamer.rs b/src/voice/streamer.rs
index bf77b1d..cd7cae8 100644
--- a/src/voice/streamer.rs
+++ b/src/voice/streamer.rs
@@ -100,8 +100,10 @@ impl<R: Read + Send> AudioSource for InputSource<R> {
/// Opens an audio file through `ffmpeg` and creates an audio source.
pub fn ffmpeg<P: AsRef<OsStr>>(path: P) -> Result<Box<AudioSource>> {
- let path = path.as_ref();
+ _ffmpeg(path.as_ref())
+}
+fn _ffmpeg(path: &OsStr) -> Result<Box<AudioSource>> {
// Will fail if the path is not to a file on the fs. Likely a YouTube URI.
let is_stereo = is_stereo(path).unwrap_or(false);
let stereo_val = if is_stereo { "2" } else { "1" };
@@ -133,7 +135,11 @@ pub fn ffmpeg<P: AsRef<OsStr>>(path: P) -> Result<Box<AudioSource>> {
/// Creates a streamed audio source from a DCA file.
/// Currently only accepts the DCA1 format.
pub fn dca<P: AsRef<OsStr>>(path: P) -> StdResult<Box<AudioSource>, DcaError> {
- let file = File::open(path.as_ref()).map_err(DcaError::IoError)?;
+ _dca(path.as_ref())
+}
+
+fn _dca(path: &OsStr) -> StdResult<Box<AudioSource>, DcaError> {
+ let file = File::open(path).map_err(DcaError::IoError)?;
let mut reader = BufReader::new(file);