diff options
| author | Zeyla Hellyer <[email protected]> | 2017-10-10 20:08:11 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-10-10 20:08:11 -0700 |
| commit | 93e0a4215c915b98cf433ac6d0bcfbc60f0168ec (patch) | |
| tree | 727111506d1f89cd8a511b8b79c102131222421f /src/model/mod.rs | |
| parent | Resume on resumable session invalidations (diff) | |
| download | serenity-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/model/mod.rs')
| -rw-r--r-- | src/model/mod.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/model/mod.rs b/src/model/mod.rs index 0817094..64987e1 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -32,11 +32,12 @@ pub use self::voice::*; pub use self::webhook::*; use chrono::NaiveDateTime; +use parking_lot::RwLock; use self::utils::*; use serde::de::Visitor; use std::collections::HashMap; use std::fmt::{Display, Formatter, Result as FmtResult}; -use std::sync::{Arc, RwLock}; +use std::sync::Arc; use internal::prelude::*; #[cfg(feature = "utils")] @@ -67,7 +68,7 @@ macro_rules! id_u64 { self } } - + impl From<u64> for $name { fn from(id_as_u64: u64) -> $name { $name(id_as_u64) |