pub struct GuildView<'a, K, V, B>{ /* 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>
impl<'a, K, V, B> GuildView<'a, K, V, B>
Sourcepub const fn guild_id(&self) -> GuildId
pub const fn guild_id(&self) -> GuildId
Returns the guild this view is about.
discord.js counterpart: a guild manager’s guild.
Sourcepub const fn is_enabled(&self) -> bool
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).
Sourcepub fn get(&self, id: K) -> Option<Arc<V>>
pub fn get(&self, id: K) -> Option<Arc<V>>
Returns the guild’s entry with this ID.
discord.js counterpart: Collection#get.
Sourcepub fn contains(&self, id: K) -> bool
pub fn contains(&self, id: K) -> bool
Returns whether the guild has a cached entry with this ID.
discord.js counterpart: Collection#has.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of the guild’s cached entries.
discord.js counterpart: Collection#size.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether nothing of the guild is cached.
discord.js counterpart: cache.size === 0.