diff options
| author | zeyla <[email protected]> | 2018-07-05 09:26:46 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2018-07-05 09:26:46 -0700 |
| commit | 9e560628deb1cf66e0c5029f41a79404fadffb40 (patch) | |
| tree | 83b28db08fd1c26fdfd577334252c2b6c618fcf7 /src/cache/mod.rs | |
| parent | Monomorphize all functions (diff) | |
| download | serenity-9e560628deb1cf66e0c5029f41a79404fadffb40.tar.xz serenity-9e560628deb1cf66e0c5029f41a79404fadffb40.zip | |
Make the Cache Update API public (#344)
This commit makes the Cache Update API public, allowing users to manually update
the cache, as well as implementing the caching API on their own types to work
with mutating the cache.
The motivation for this indirectly comes from a message cache: if a user has
multiple processes that can receive cache updates (either splitting a bot's
shards into multiple processes or other processes like web panels or pub/sub
channels), then this will allow them to easily mutate the cache and feed all
types implementing the CacheUpdate trait into `Cache::update`.
Diffstat (limited to 'src/cache/mod.rs')
| -rw-r--r-- | src/cache/mod.rs | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/cache/mod.rs b/src/cache/mod.rs index e0a5ee6..3bf5a5a 100644 --- a/src/cache/mod.rs +++ b/src/cache/mod.rs @@ -56,7 +56,7 @@ use std::{ mod cache_update; -pub(crate) use self::cache_update::*; +pub use self::cache_update::CacheUpdate; /// A cache of all events received over a [`Shard`], where storing at least /// some data from the event is possible. @@ -163,6 +163,12 @@ pub struct Cache { } impl Cache { + /// Creates a new cache. + #[inline] + pub fn new() -> Self { + Self::default() + } + /// Fetches the number of [`Member`]s that have not had data received. /// /// The important detail to note here is that this is the number of @@ -664,8 +670,18 @@ impl Cache { self.categories.get(&channel_id).cloned() } - #[cfg(feature = "client")] - pub(crate) fn update<E: CacheUpdate>(&mut self, e: &mut E) -> Option<E::Output> { + /// Updates the cache with the update implementation for an event or other + /// custom update implementation. + /// + /// Refer to the documentation for [`CacheUpdate`] for more information. + /// + /// # Examples + /// + /// Refer to the [`CacheUpdate` examples]. + /// + /// [`CacheUpdate`]: trait.CacheUpdate.html + /// [`CacheUpdate` examples]: trait.CacheUpdate.html#examples + pub fn update<E: CacheUpdate>(&mut self, e: &mut E) -> Option<E::Output> { e.update(self) } |