rive_cache_inmemory/
stats.rs

1use crate::InMemoryCache;
2
3/// An interface for iterating over the various resources in the cache.
4///
5/// Example:
6///
7/// ```no_run
8/// use rive_cache_inmemory::InMemoryCache;
9///
10/// let cache = InMemoryCache::new();
11///
12/// // later in the code...
13/// let count = cache.stats().users();
14/// println!("users cached: {count}");
15/// ```
16#[derive(Clone, Debug)]
17pub struct InMemoryCacheStats<'a>(&'a InMemoryCache);
18
19impl<'a> InMemoryCacheStats<'a> {
20    /// Create a new stats interface instance.
21    pub(super) const fn new(cache: &'a InMemoryCache) -> Self {
22        Self(cache)
23    }
24
25    /// Number of users in the cache.
26    pub fn users(&'a self) -> usize {
27        self.0.users.len()
28    }
29
30    /// Number of servers in the cache.
31    pub fn serevrs(&'a self) -> usize {
32        self.0.servers.len()
33    }
34
35    /// Number of channels in the cache.
36    pub fn channels(&'a self) -> usize {
37        self.0.channels.len()
38    }
39
40    /// Number of messages in the cache.
41    pub fn messages(&'a self) -> usize {
42        self.0.messages.len()
43    }
44
45    /// Number of emojis in the cache.
46    pub fn emojis(&'a self) -> usize {
47        self.0.emojis.len()
48    }
49
50    /// Number of members in the cache.
51    pub fn members(&'a self) -> usize {
52        self.0.members.len()
53    }
54}