pub struct PermissionCalculator<'a> { /* private fields */ }
Available on crate feature permission-calculator only.
Expand description

Calculate the permissions of a member.

Using the member calculator you can calculate the member’s permissions in the root-level of a guild or in a given channel.

Implementations§

source§

impl<'a> PermissionCalculator<'a>

source

pub const fn new( guild_id: Id<GuildMarker>, user_id: Id<UserMarker>, everyone_role: Permissions, member_roles: &'a [(Id<RoleMarker>, Permissions)] ) -> Self

Create a calculator to calculate the permissions of a member.

everyone_role is the permissions of the @everyone role on a guild-level; the permissions may be empty. The @everyone role’s ID is the same as that of the guild_id.

The provided member’s roles should not contain the @everyone role.

source

pub const fn owner_id(self, owner_id: Id<UserMarker>) -> Self

Configure the ID of the owner of the guild.

This should be used if you don’t want to manually take the user ID and owner ID in account beforehand.

If the member’s ID is the same as the owner’s ID then permission calculating methods such as root will return all permissions enabled.

source

pub const fn root(&self) -> Permissions

Calculate the guild-level permissions of a member.

source

pub const fn in_channel( self, channel_type: ChannelType, channel_overwrites: &[PermissionOverwrite] ) -> Permissions

Calculate the permissions of the member in a channel, taking into account a combination of the guild-level permissions and channel-level permissions.

Note that this method will not return guild-level permissions such as Manage Guild Expressions; if you need the guild-level permissions use root.

§Conditional exclusions

When the member doesn’t have the “View Channel” permission then an empty permission set will be returned. This will happen in the following circumstances:

  • When the permission is denied on the role level and isn’t enabled on a role or member permission overwrite;
  • When the permission is denied on a role permission overwrite but isn’t enabled on a member permission overwrite; or
  • When permission isn’t enabled on a guild level and isn’t enabled via a permission overwrite.

When the Send Messages permission is denied and is not similarly enabled like above then the Attach Files, Embed Links, Mention Everyone, and Send TTS Messages permissions will not be present in the returned permission set.

§Channel-based exclusions

Permissions are removed based on the type of a channel. For example, when calculating the permissions of a voice channel we can know that if Send Messages is granted on a guild-level to everyone then it is omitted from the permissions for a specific channel.

§Stage Channels

When the given channel type is a guild stage channel then the following permissions will be removed:

§Text Channels

When the given channel type is a guild text channel then the following permissions will be removed:

§Voice Channels

When the given channel type is a guild voice channel then the following permissions will be removed:

§Guild-based exclusions

The following guild-level permissions will always be removed:

If you need to know a member’s guild-level permissions - such as whether they have the View Audit Log permission - use root instead.

§Examples

See the crate-level documentation for an example.

Trait Implementations§

source§

impl<'a> Clone for PermissionCalculator<'a>

source§

fn clone(&self) -> PermissionCalculator<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for PermissionCalculator<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> PartialEq for PermissionCalculator<'a>

source§

fn eq(&self, other: &PermissionCalculator<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> Eq for PermissionCalculator<'a>

source§

impl<'a> StructuralPartialEq for PermissionCalculator<'a>

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.