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 /tests | |
| 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 'tests')
| -rw-r--r-- | tests/test_channels.rs | 4 | ||||
| -rw-r--r-- | tests/test_formatters.rs | 4 |
2 files changed, 6 insertions, 2 deletions
diff --git a/tests/test_channels.rs b/tests/test_channels.rs index 7a3f9c3..51e8510 100644 --- a/tests/test_channels.rs +++ b/tests/test_channels.rs @@ -1,10 +1,12 @@ +extern crate parking_lot; extern crate serenity; #[cfg(feature = "utils")] mod utils { + use parking_lot::RwLock; use serenity::model::*; use std::collections::HashMap; - use std::sync::{Arc, RwLock}; + use std::sync::Arc; fn group() -> Group { Group { diff --git a/tests/test_formatters.rs b/tests/test_formatters.rs index b48c648..fbc60ca 100644 --- a/tests/test_formatters.rs +++ b/tests/test_formatters.rs @@ -1,3 +1,4 @@ +extern crate parking_lot; extern crate serenity; use serenity::model::*; @@ -14,8 +15,9 @@ fn test_formatters() { #[cfg(feature = "utils")] #[test] fn test_mention() { + use parking_lot::RwLock; use serenity::utils::Colour; - use std::sync::{Arc, RwLock}; + use std::sync::Arc; let channel = Channel::Guild(Arc::new(RwLock::new(GuildChannel { bitrate: None, |