Skip to main content

ChannelView

Struct ChannelView 

Source
pub struct ChannelView<'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 channel (messages), for one channel, as returned by Cache::messages.

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

discord.js counterpart: channel.messages.cache.

§Examples

use djs_cache::{Cache, CacheConfig, Limit};
use djs_model::id::{ChannelId, MessageId};

let cache = Cache::with_config(CacheConfig::builder().messages(Limit::Max(100)).build());
let messages = cache.messages(ChannelId::new(1));
assert!(messages.is_enabled());
assert!(messages.get(MessageId::new(2)).is_none());

Implementations§

Source§

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

Source

pub const fn channel_id(&self) -> ChannelId

Returns the channel this view is about.

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

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 channel’s entry with this ID.

discord.js counterpart: Collection#get.

Source

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

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

discord.js counterpart: Collection#has.

Source

pub fn len(&self) -> usize

Returns the number of the channel’s cached entries.

discord.js counterpart: Collection#size.

Source

pub fn is_empty(&self) -> bool

Returns whether nothing of the channel is cached.

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

Source

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

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

discord.js counterpart: Collection#keys of MessageManager#cache.

Source

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

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

discord.js counterpart: Collection#values of MessageManager#cache.

Trait Implementations§

Source§

impl<K, V, B> Debug for ChannelView<'_, 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 ChannelView<'a, K, V, B>

§

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

§

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

§

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

§

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

§

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

§

impl<'a, K, V, B> UnsafeUnpin for ChannelView<'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.