aboutsummaryrefslogtreecommitdiff
path: root/src/client/context.rs
diff options
context:
space:
mode:
authorLakelezz <[email protected]>2018-12-18 20:55:32 +0100
committerAlex M. M <[email protected]>2018-12-18 20:55:32 +0100
commit8cb1bdc6cf992cc55810f5af753666d54f2237d5 (patch)
tree052e2f425a6117e45323886bb2b2b683b6d5a1e8 /src/client/context.rs
parentMutably borrow on `ChannelId`'s `edit`-method. (#447) (diff)
downloadserenity-8cb1bdc6cf992cc55810f5af753666d54f2237d5.tar.xz
serenity-8cb1bdc6cf992cc55810f5af753666d54f2237d5.zip
Remove global Cache (#448)
* Update to use Rust 2018. * Update examples and use Rust 2018. * Pass cache via `Context` around instead of being global. * Remove `lazy_static` from `cache`-feature. * Update examples to use `Context`'s cache. * Replace cache's update-timeout-setting with `update_cache_timeout`. * Update documentation to stop using global cache. * Move `HttpAndCache` to `lib.rs`. * Add `__nonexhaustive`-field to `CacheAndHttp`. * Add `__nonexhaustive` in `CacheAndHttp`-initialisers. * Avoid `__nonexhaustive`-usage in doctest. * Remove unnecessary comma in `cfg`-attribute.
Diffstat (limited to 'src/client/context.rs')
-rw-r--r--src/client/context.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/client/context.rs b/src/client/context.rs
index 8a08213..ff92f5e 100644
--- a/src/client/context.rs
+++ b/src/client/context.rs
@@ -1,5 +1,4 @@
use crate::builder::EditProfile;
-use crate::CACHE;
use crate::client::bridge::gateway::ShardMessenger;
use crate::error::Result;
use crate::gateway::InterMessage;
@@ -14,6 +13,10 @@ use std::sync::{
use typemap::ShareMap;
use crate::utils::VecMap;
use crate::utils::vecmap_to_json_map;
+#[cfg(feature = "cache")]
+pub use crate::cache::Cache;
+#[cfg(feature = "cache")]
+use parking_lot::RwLock;
/// The context is a general utility struct provided on event dispatches, which
/// helps with dealing with the current "context" of the event dispatch.
@@ -41,6 +44,8 @@ pub struct Context {
pub shard: ShardMessenger,
/// The ID of the shard this context is related to.
pub shard_id: u64,
+ #[cfg(feature = "cache")]
+ pub cache: Arc<RwLock<Cache>>,
}
impl Context {
@@ -49,11 +54,14 @@ impl Context {
data: Arc<Mutex<ShareMap>>,
runner_tx: Sender<InterMessage>,
shard_id: u64,
+ cache: Arc<RwLock<Cache>>,
) -> Context {
Context {
shard: ShardMessenger::new(runner_tx),
shard_id,
data,
+ #[cfg(feature = "cache")]
+ cache,
}
}
@@ -94,7 +102,7 @@ impl Context {
feature_cache! {
{
- let cache = CACHE.read();
+ let cache = self.cache.read();
map.insert("username", Value::String(cache.user.name.clone()));