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/channel/channel_id.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/channel/channel_id.rs')
| -rw-r--r-- | src/model/channel/channel_id.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/model/channel/channel_id.rs b/src/model/channel/channel_id.rs index f728191..4034fb9 100644 --- a/src/model/channel/channel_id.rs +++ b/src/model/channel/channel_id.rs @@ -224,14 +224,14 @@ impl ChannelId { /// Search the cache for the channel with the Id. #[cfg(feature = "cache")] - pub fn find(&self) -> Option<Channel> { CACHE.read().unwrap().channel(*self) } + pub fn find(&self) -> Option<Channel> { CACHE.read().channel(*self) } /// Search the cache for the channel. If it can't be found, the channel is /// requested over REST. pub fn get(&self) -> Result<Channel> { #[cfg(feature = "cache")] { - if let Some(channel) = CACHE.read().unwrap().channel(*self) { + if let Some(channel) = CACHE.read().channel(*self) { return Ok(channel); } } @@ -311,13 +311,13 @@ impl ChannelId { }; Some(match channel { - Guild(channel) => channel.read().unwrap().name().to_string(), - Group(channel) => match channel.read().unwrap().name() { + Guild(channel) => channel.read().name().to_string(), + Group(channel) => match channel.read().name() { Cow::Borrowed(name) => name.to_string(), Cow::Owned(name) => name, }, - Category(category) => category.read().unwrap().name().to_string(), - Private(channel) => channel.read().unwrap().name(), + Category(category) => category.read().name().to_string(), + Private(channel) => channel.read().name(), }) } |