aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-10-10 20:08:11 -0700
committerZeyla Hellyer <[email protected]>2017-10-10 20:08:11 -0700
commit93e0a4215c915b98cf433ac6d0bcfbc60f0168ec (patch)
tree727111506d1f89cd8a511b8b79c102131222421f /src/lib.rs
parentResume on resumable session invalidations (diff)
downloadserenity-93e0a4215c915b98cf433ac6d0bcfbc60f0168ec.tar.xz
serenity-93e0a4215c915b98cf433ac6d0bcfbc60f0168ec.zip
Switch to parking_lot::{Mutex, RwLock}
Switch to the `parking_lot` crate's implementations of `std::sync::Mutex` and `std::sync::RwLock`, which are more efficient. A writeup on why `parking_lot` is more efficient can be read here: <https://github.com/Amanieu/parking_lot> Upgrade path: Modify `mutex.lock().unwrap()` usage to `mutex.lock()` (not needing to unwrap or handle a result), and `rwlock.read().unwrap()`/`rwlock.write().unwrap()` usage to `rwlock.read()` and `rwlock.write()`. For example, modify: ```rust use serenity::CACHE; println!("{}", CACHE.read().unwrap().user.id); ``` to: ```rust use serenity::CACHE; println!("{}", CACHE.read().user.id); ```
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs14
1 files changed, 3 insertions, 11 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 612972a..a3710eb 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -107,6 +107,7 @@ extern crate serde_json;
extern crate lazy_static;
extern crate chrono;
+extern crate parking_lot;
extern crate serde;
#[cfg(feature = "utils")]
@@ -125,8 +126,6 @@ extern crate multipart;
extern crate native_tls;
#[cfg(feature = "voice")]
extern crate opus;
-#[cfg(feature = "client")]
-extern crate parking_lot;
#[cfg(feature = "voice")]
extern crate sodiumoxide;
#[cfg(feature = "threadpool")]
@@ -172,7 +171,7 @@ pub use client::Client;
#[cfg(feature = "cache")]
use cache::Cache;
#[cfg(feature = "cache")]
-use std::sync::RwLock;
+use parking_lot::RwLock;
#[cfg(feature = "cache")]
lazy_static! {
@@ -197,16 +196,9 @@ lazy_static! {
/// ```rust,ignore
/// use serenity::CACHE;
///
- /// println!("{}", CACHE.read().unwrap().user.id);
+ /// println!("{}", CACHE.read().user.id);
/// ```
///
- /// By `unwrap()`ing, the thread managing an event dispatch will be blocked
- /// until the guard can be opened.
- ///
- /// If you do not want to block the current thread, you may instead use
- /// `RwLock::try_read`. Refer to `RwLock`'s documentation in the stdlib for
- /// more information.
- ///
/// [`CurrentUser`]: model/struct.CurrentUser.html
/// [`Cache`]: cache/struct.Cache.html
/// [cache module documentation]: cache/index.html