diff options
| author | Zeyla Hellyer <[email protected]> | 2018-02-04 07:50:53 -0800 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2018-02-04 07:54:31 -0800 |
| commit | a9966371def331cd848f642e222627ee9decf354 (patch) | |
| tree | 316c75854ddea79230f98b66708c3f815b836227 /src/utils | |
| parent | Partially revert the video url change (diff) | |
| download | serenity-a9966371def331cd848f642e222627ee9decf354.tar.xz serenity-a9966371def331cd848f642e222627ee9decf354.zip | |
Rewrite the library to use Futures
Rewrites the library to use Futures. This rewrites all of the gateway,
client, cache, most model methods, HTTP, and in a later commit the
framework and voice.
HTTP has been mostly rewritten to be ergonomic so that it can be used by
the user, and has been upgraded to hyper v0.11.
The gateway now uses `tokio-tungstenite` v0.4.
The client isn't yet in a working state.
The models now have a `client` optionally attached to them to make use
of `http` and `cache`-utilizing methods. The client isn't needed, in the
case that someone is using the library just to deserialize models.
The cache is now built around `Rc`s and `RefCell`s, instead of `Arc`s
and `RwLock`s.
Refer to example 01 for a working example. Much of the library still
doesn't work.
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/mod.rs | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/src/utils/mod.rs b/src/utils/mod.rs index de75632..0235a26 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -20,11 +20,6 @@ use std::hash::{BuildHasher, Hash}; use std::io::Read; use std::path::Path; -#[cfg(feature = "cache")] -use cache::Cache; -#[cfg(feature = "cache")] -use CACHE; - /// Converts a HashMap into a final `serde_json::Map` representation. pub fn hashmap_to_json_map<H, T>(map: HashMap<T, Value, H>) -> Map<String, Value> where H: BuildHasher, T: Eq + Hash + ToString { @@ -461,45 +456,3 @@ pub fn parse_quotes(s: &str) -> Vec<String> { /// ``` #[inline] pub fn shard_id(guild_id: u64, shard_count: u64) -> u64 { (guild_id >> 22) % shard_count } - -/// A function for doing automatic `read`ing (and the releasing of the guard as well) -/// This is particularly useful if you just want to use the cache for this one time, -/// or don't want to be messing with the `RwLock` directly. -/// -/// # Examples -/// -/// Return the bot's id -/// -/// ```rust,ignore -/// use serenity::utils; -/// -/// // assuming that the id is `1234`: -/// assert_eq!(1234, utils::with_cache(|cache| cache.user.id)); -/// ``` -#[cfg(feature = "cache")] -pub fn with_cache<T, F>(f: F) -> T - where F: Fn(&Cache) -> T { - let cache = CACHE.read(); - f(&cache) -} - -/// Like [`with_cache`] but as the name says, allows for modifications to be done. -/// -/// # Examples -/// -/// Return the bot's id, and changes the shard count -/// -/// ```rust,ignore -/// use serenity::utils; -/// -/// // assuming that the id is `1234`: -/// assert_eq!(1234, utils::with_cache_mut(|cache| { cache.shard_count = 8; cache.user.id })); -/// ``` -/// -/// [`with_cache`]: #fn.with_cache -#[cfg(feature = "cache")] -pub fn with_cache_mut<T, F>(mut f: F) -> T - where F: FnMut(&mut Cache) -> T { - let mut cache = CACHE.write(); - f(&mut cache) -} |