1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
use twilight_model::id::{ChannelId, GuildId};
use super::InMemoryCache;
#[derive(Clone, Debug)]
pub struct InMemoryCacheStats<'a>(&'a InMemoryCache);
impl<'a> InMemoryCacheStats<'a> {
pub(super) const fn new(cache: &'a InMemoryCache) -> Self {
Self(cache)
}
pub const fn cache_ref(&'a self) -> &'a InMemoryCache {
self.0
}
pub const fn into_cache(self) -> &'a InMemoryCache {
self.0
}
pub fn channel_messages(&self, channel_id: ChannelId) -> Option<usize> {
let channel = self.0 .0.messages.get(&channel_id)?;
Some(channel.len())
}
pub fn channel_voice_states(&self, channel_id: ChannelId) -> Option<usize> {
let channel = self.0 .0.voice_state_channels.get(&channel_id)?;
Some(channel.len())
}
pub fn emojis(&self) -> usize {
self.0 .0.emojis.len()
}
pub fn groups(&self) -> usize {
self.0 .0.groups.len()
}
pub fn guilds(&self) -> usize {
self.0 .0.guilds.len()
}
pub fn guild_channels(&self, guild_id: GuildId) -> Option<usize> {
let guild = self.0 .0.guild_channels.get(&guild_id)?;
Some(guild.len())
}
pub fn guild_emojis(&self, guild_id: GuildId) -> Option<usize> {
let guild = self.0 .0.guild_emojis.get(&guild_id)?;
Some(guild.len())
}
pub fn guild_members(&self, guild_id: GuildId) -> Option<usize> {
let guild = self.0 .0.guild_members.get(&guild_id)?;
Some(guild.len())
}
pub fn guild_presences(&self, guild_id: GuildId) -> Option<usize> {
let guild = self.0 .0.guild_presences.get(&guild_id)?;
Some(guild.len())
}
pub fn guild_roles(&self, guild_id: GuildId) -> Option<usize> {
let guild = self.0 .0.guild_roles.get(&guild_id)?;
Some(guild.len())
}
pub fn guild_voice_states(&self, guild_id: GuildId) -> Option<usize> {
let guild = self.0 .0.voice_state_guilds.get(&guild_id)?;
Some(guild.len())
}
pub fn members(&self) -> usize {
self.0 .0.members.len()
}
pub fn presences(&self) -> usize {
self.0 .0.presences.len()
}
pub fn private_channels(&self) -> usize {
self.0 .0.channels_private.len()
}
pub fn roles(&self) -> usize {
self.0 .0.roles.len()
}
pub fn unavailable_guilds(&self) -> usize {
self.0 .0.unavailable_guilds.len()
}
pub fn users(&self) -> usize {
self.0 .0.users.len()
}
pub fn voice_states(&self) -> usize {
self.0 .0.voice_states.len()
}
}
#[cfg(test)]
mod tests {
use super::InMemoryCacheStats;
use static_assertions::assert_impl_all;
use std::fmt::Debug;
assert_impl_all!(InMemoryCacheStats<'_>: Clone, Debug, Send, Sync);
}