aboutsummaryrefslogtreecommitdiff
path: root/src/model/guild/mod.rs
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/guild/mod.rs
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/guild/mod.rs')
-rw-r--r--src/model/guild/mod.rs32
1 files changed, 25 insertions, 7 deletions
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,