diff options
| author | Lakelezz <[email protected]> | 2018-12-18 20:55:32 +0100 |
|---|---|---|
| committer | Alex M. M <[email protected]> | 2018-12-18 20:55:32 +0100 |
| commit | 8cb1bdc6cf992cc55810f5af753666d54f2237d5 (patch) | |
| tree | 052e2f425a6117e45323886bb2b2b683b6d5a1e8 /src/client/bridge | |
| parent | Mutably borrow on `ChannelId`'s `edit`-method. (#447) (diff) | |
| download | serenity-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/bridge')
| -rw-r--r-- | src/client/bridge/gateway/shard_manager.rs | 10 | ||||
| -rw-r--r-- | src/client/bridge/gateway/shard_queuer.rs | 3 | ||||
| -rw-r--r-- | src/client/bridge/gateway/shard_runner.rs | 7 |
3 files changed, 19 insertions, 1 deletions
diff --git a/src/client/bridge/gateway/shard_manager.rs b/src/client/bridge/gateway/shard_manager.rs index 45926ef..579b003 100644 --- a/src/client/bridge/gateway/shard_manager.rs +++ b/src/client/bridge/gateway/shard_manager.rs @@ -1,5 +1,6 @@ use crate::gateway::InterMessage; use crate::internal::prelude::*; +use crate::CacheAndHttp; use parking_lot::Mutex; use std::{ collections::{HashMap, VecDeque}, @@ -50,14 +51,17 @@ use crate::client::bridge::voice::ClientVoiceManager; /// # use serenity::client::bridge::voice::ClientVoiceManager; /// # #[cfg(feature = "voice")] /// # use serenity::model::id::UserId; +/// # #[cfg(feature = "cache")] +/// # use serenity::cache::Cache; /// # /// # #[cfg(feature = "framework")] /// # fn try_main() -> Result<(), Box<Error>> { /// # -/// use parking_lot::Mutex; +/// use parking_lot::{Mutex, RwLock}; /// use serenity::client::bridge::gateway::{ShardManager, ShardManagerOptions}; /// use serenity::client::EventHandler; /// use serenity::http; +/// use serenity::CacheAndHttp; /// use std::sync::Arc; /// use std::env; /// use threadpool::ThreadPool; @@ -76,6 +80,7 @@ use crate::client::bridge::voice::ClientVoiceManager; /// let event_handler = Arc::new(Handler); /// let framework = Arc::new(Mutex::new(None)); /// let threadpool = ThreadPool::with_name("my threadpool".to_owned(), 5); +/// let cache_and_http = Arc::new(CacheAndHttp::default()); /// /// ShardManager::new(ShardManagerOptions { /// data: &data, @@ -92,6 +97,7 @@ use crate::client::bridge::voice::ClientVoiceManager; /// # #[cfg(feature = "voice")] /// # voice_manager: &Arc::new(Mutex::new(ClientVoiceManager::new(0, UserId(0)))), /// ws_url: &gateway_url, +/// cache_and_http: &cache_and_http, /// }); /// # Ok(()) /// # } @@ -151,6 +157,7 @@ impl ShardManager { #[cfg(feature = "voice")] voice_manager: Arc::clone(opt.voice_manager), ws_url: Arc::clone(opt.ws_url), + cache_and_http: Arc::clone(&opt.cache_and_http), }; thread::spawn(move || { @@ -362,4 +369,5 @@ pub struct ShardManagerOptions<'a, H: EventHandler + Send + Sync + 'static> { #[cfg(feature = "voice")] pub voice_manager: &'a Arc<Mutex<ClientVoiceManager>>, pub ws_url: &'a Arc<Mutex<String>>, + pub cache_and_http: &'a Arc<CacheAndHttp>, } diff --git a/src/client/bridge/gateway/shard_queuer.rs b/src/client/bridge/gateway/shard_queuer.rs index 5152249..12df4c8 100644 --- a/src/client/bridge/gateway/shard_queuer.rs +++ b/src/client/bridge/gateway/shard_queuer.rs @@ -1,5 +1,6 @@ use crate::gateway::Shard; use crate::internal::prelude::*; +use crate::CacheAndHttp; use parking_lot::Mutex; use std::{ collections::{HashMap, VecDeque}, @@ -85,6 +86,7 @@ pub struct ShardQueuer<H: EventHandler + Send + Sync + 'static> { pub voice_manager: Arc<Mutex<ClientVoiceManager>>, /// A copy of the URI to use to connect to the gateway. pub ws_url: Arc<Mutex<String>>, + pub cache_and_http: Arc<CacheAndHttp>, } impl<H: EventHandler + Send + Sync + 'static> ShardQueuer<H> { @@ -188,6 +190,7 @@ impl<H: EventHandler + Send + Sync + 'static> ShardQueuer<H> { #[cfg(feature = "voice")] voice_manager: Arc::clone(&self.voice_manager), shard, + cache_and_http: Arc::clone(&self.cache_and_http), }); let runner_info = ShardRunnerInfo { diff --git a/src/client/bridge/gateway/shard_runner.rs b/src/client/bridge/gateway/shard_runner.rs index 5e2a1ff..fe71462 100644 --- a/src/client/bridge/gateway/shard_runner.rs +++ b/src/client/bridge/gateway/shard_runner.rs @@ -2,6 +2,7 @@ use crate::gateway::{InterMessage, ReconnectType, Shard, ShardAction}; use crate::internal::prelude::*; use crate::internal::ws_impl::{ReceiverExt, SenderExt}; use crate::model::event::{Event, GatewayEvent}; +use crate::CacheAndHttp; use parking_lot::Mutex; use serde::Deserialize; use std::{ @@ -32,6 +33,7 @@ use crate::framework::Framework; #[cfg(feature = "voice")] use super::super::voice::ClientVoiceManager; + /// A runner for managing a [`Shard`] and its respective WebSocket client. /// /// [`Shard`]: ../../../gateway/struct.Shard.html @@ -49,6 +51,7 @@ pub struct ShardRunner<H: EventHandler + Send + Sync + 'static> { threadpool: ThreadPool, #[cfg(feature = "voice")] voice_manager: Arc<Mutex<ClientVoiceManager>>, + cache_and_http: Arc<CacheAndHttp>, } impl<H: EventHandler + Send + Sync + 'static> ShardRunner<H> { @@ -68,6 +71,7 @@ impl<H: EventHandler + Send + Sync + 'static> ShardRunner<H> { threadpool: opt.threadpool, #[cfg(feature = "voice")] voice_manager: opt.voice_manager, + cache_and_http: opt.cache_and_http, } } @@ -212,6 +216,7 @@ impl<H: EventHandler + Send + Sync + 'static> ShardRunner<H> { &self.runner_tx, &self.threadpool, self.shard.shard_info()[0], + Arc::clone(&self.cache_and_http), ); } @@ -493,4 +498,6 @@ pub struct ShardRunnerOptions<H: EventHandler + Send + Sync + 'static> { pub threadpool: ThreadPool, #[cfg(feature = "voice")] pub voice_manager: Arc<Mutex<ClientVoiceManager>>, + #[cfg(feature = "cache")] + pub cache_and_http: Arc<CacheAndHttp>, } |