Skip to main content

GuildView

Struct GuildView 

Source
pub struct GuildView<'a, K, V, B>
where K: Eq + Hash + Copy + Send + Sync + 'static, V: Send + Sync + 'static, B: Backend,
{ /* private fields */ }
Expand description

A resource kept per guild (roles, emojis, stickers, members, …), for one guild, as returned by Cache::roles, Cache::members and the like.

A view of a disabled resource is empty. Every read is a snapshot: the cache may change right after it.

discord.js counterpart: guild.roles.cache, guild.members.cache, ….

§Examples

use djs_cache::Cache;
use djs_model::id::{GuildId, RoleId};

let cache = Cache::new();
let roles = cache.roles(GuildId::new(1));
assert!(roles.is_enabled());
assert!(roles.get(RoleId::new(2)).is_none());
// Members are not cached by default.
assert!(!cache.members(GuildId::new(1)).is_enabled());

Implementations§

Source§

impl<'a, K, V, B> GuildView<'a, K, V, B>
where K: Eq + Hash + Copy + Send + Sync + 'static, V: Send + Sync + 'static, B: Backend,

Source

pub const fn guild_id(&self) -> GuildId

Returns the guild this view is about.

discord.js counterpart: a guild manager’s guild.

Source

pub const fn is_enabled(&self) -> bool

Returns whether the resource is cached at all.

discord.js counterpart: none (a manager’s cache always exists in discord.js).

Source

pub fn get(&self, id: K) -> Option<Arc<V>>

Returns the guild’s entry with this ID.

discord.js counterpart: Collection#get.

Source

pub fn contains(&self, id: K) -> bool

Returns whether the guild has a cached entry with this ID.

discord.js counterpart: Collection#has.

Source

pub fn len(&self) -> usize

Returns the number of the guild’s cached entries.

discord.js counterpart: Collection#size.

Source

pub fn is_empty(&self) -> bool

Returns whether nothing of the guild is cached.

discord.js counterpart: cache.size === 0.

Source

pub fn keys(&self) -> Vec<K>

Returns the IDs of the guild’s cached entries, in no particular order.

discord.js counterpart: Collection#keys of a guild manager’s cache.

Source

pub fn values(&self) -> Vec<Arc<V>>

Returns the guild’s cached entries, in no particular order.

discord.js counterpart: Collection#values of a guild manager’s cache.

Trait Implementations§

Source§

impl<K, V, B> Debug for GuildView<'_, K, V, B>
where K: Eq + Hash + Copy + Send + Sync + 'static, V: Send + Sync + 'static, B: Backend,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, K, V, B> !RefUnwindSafe for GuildView<'a, K, V, B>

§

impl<'a, K, V, B> !UnwindSafe for GuildView<'a, K, V, B>

§

impl<'a, K, V, B> Freeze for GuildView<'a, K, V, B>

§

impl<'a, K, V, B> Send for GuildView<'a, K, V, B>

§

impl<'a, K, V, B> Sync for GuildView<'a, K, V, B>

§

impl<'a, K, V, B> Unpin for GuildView<'a, K, V, B>

§

impl<'a, K, V, B> UnsafeUnpin for GuildView<'a, K, V, B>

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