Skip to main content

Visibility

Struct Visibility 

Source
struct Visibility {
    source: ChannelOverwrites,
    target: ChannelOverwrites,
    read_source: Permissions,
    read_target: Permissions,
    everyone_role_id: Id<RoleMarker>,
    role_perms: HashMap<Id<RoleMarker>, Permissions>,
    reachable: HashSet<RoleGrant>,
}
Expand description

Decides whether everyone who can read the source channel could also read the target channel.

Members are split by whether either channel carries an overwrite for them personally:

  • Without one, a member’s access depends only on which roles they hold. Self::roles_preserve_visibility checks every combination of roles a member could hold — not just each role on its own, since Discord merges a member’s role overwrites before applying them.
  • With one, the member is looked up and judged on their actual roles by Self::member_preserves_visibility. Self::members_to_verify lists only those whose personal overwrite could make a difference.

Fields§

§source: ChannelOverwrites§target: ChannelOverwrites§read_source: Permissions

What a member needs in the source, from read_source_requirement.

§read_target: Permissions

What a member needs in the target, from read_target_requirement.

§everyone_role_id: Id<RoleMarker>§role_perms: HashMap<Id<RoleMarker>, Permissions>§reachable: HashSet<RoleGrant>

Every grant a member without personal overwrites can hold.

Implementations§

Source§

impl Visibility

Source

fn new( source_overwrites: &[PermissionOverwrite], target_overwrites: &[PermissionOverwrite], read_source: Permissions, read_target: Permissions, role_perms: HashMap<Id<RoleMarker>, Permissions>, everyone_role_id: Id<RoleMarker>, ) -> Self

Source

fn everyone_grant(&self) -> RoleGrant

The grant of @everyone, which every member holds. Its overwrite is applied separately, so it contributes base permissions only.

Source

fn role_grant(&self, role_id: Id<RoleMarker>) -> RoleGrant

Source

fn base_of(&self, role_id: Id<RoleMarker>) -> Permissions

Masked to the base permissions that can change the outcome of channel_permissions, so that equivalent roles collapse into one RoleGrant and Self::reachable_grants stays small.

Source

fn reachable_grants(&self) -> HashSet<RoleGrant>

Closes @everyone’s grant under union with every other role’s grant.

Why not enumerate role subsets: that is exponential in the number of roles, while the masked grants have only a few bits, so the closure stays small no matter how many roles the guild has.

Roles named only by an overwrite are included too: a role created after the role cache was filled still restricts whoever holds it.

Source

fn source_permissions( &self, grant: RoleGrant, member: (Permissions, Permissions), ) -> Permissions

Source

fn target_permissions( &self, grant: RoleGrant, member: (Permissions, Permissions), ) -> Permissions

Source

fn leaks( &self, grant: RoleGrant, source_member: (Permissions, Permissions), target_member: (Permissions, Permissions), ) -> bool

Whether a member with grant and the given personal overwrites can read the source but not the target.

Source

fn roles_preserve_visibility(&self) -> bool

Whether no combination of roles lets a member read the source but not the target, for members without personal overwrites.

Source

fn members_to_verify(&self) -> Vec<Id<UserMarker>>

Members whose personal overwrites could let them read the source but not the target, sorted by id.

A member is listed only when some role combination, together with their personal overwrites, leaks; for anyone else the outcome is the same whatever roles they actually hold, so looking them up is wasted.

Source

fn member_preserves_visibility( &self, user: Id<UserMarker>, roles: &[Id<RoleMarker>], ) -> bool

Whether user, holding roles, cannot read the source without also being able to read the target.

Trait Implementations§

Source§

impl Debug for Visibility

Source§

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

Formats the value using the given formatter. Read more

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
§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more