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/model/misc.rs | |
| 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/model/misc.rs')
| -rw-r--r-- | src/model/misc.rs | 73 |
1 files changed, 3 insertions, 70 deletions
diff --git a/src/model/misc.rs b/src/model/misc.rs index 183ddc3..898ce6f 100644 --- a/src/model/misc.rs +++ b/src/model/misc.rs @@ -1,7 +1,6 @@ //! Miscellaneous helper traits, enums, and structs for models. use super::prelude::*; -use internal::RwLockExt; #[cfg(all(feature = "model", feature = "utils"))] use std::error::Error as StdError; @@ -28,9 +27,9 @@ impl Mentionable for ChannelId { impl Mentionable for Channel { fn mention(&self) -> String { match *self { - Channel::Guild(ref x) => format!("<#{}>", x.with(|x| x.id.0)), - Channel::Private(ref x) => format!("<#{}>", x.with(|x| x.id.0)), - Channel::Group(ref x) => format!("<#{}>", x.with(|x| x.channel_id.0)), + Channel::Guild(ref x) => format!("<#{}>", x.borrow().id.0), + Channel::Private(ref x) => format!("<#{}>", x.borrow().id.0), + Channel::Group(ref x) => format!("<#{}>", x.borrow().channel_id.0), Channel::Category(_) => panic!("Categories can't be mentioned"), } } @@ -40,10 +39,6 @@ impl Mentionable for Emoji { fn mention(&self) -> String { format!("<:{}:{}>", self.name, self.id.0) } } -impl Mentionable for Member { - fn mention(&self) -> String { format!("<@{}>", self.user.with(|u| u.id.0)) } -} - impl Mentionable for RoleId { fn mention(&self) -> String { format!("<@&{}>", self.0) } } @@ -84,20 +79,6 @@ impl StdError for UserParseError { } } -#[cfg(all(feature = "model", feature = "utils"))] -impl FromStr for User { - type Err = UserParseError; - - fn from_str(s: &str) -> StdResult<Self, Self::Err> { - match utils::parse_username(s) { - Some(x) => UserId(x as u64) - .get() - .map_err(|e| UserParseError::Rest(Box::new(e))), - _ => Err(UserParseError::InvalidUsername), - } - } -} - macro_rules! impl_from_str { (id: $($id:tt, $err:ident;)*) => { $( @@ -136,49 +117,6 @@ macro_rules! impl_from_str { } )* }; - - (struct: $($struct:ty, $id:tt, $err:ident, $invalid_variant:tt, $parse_fn:ident, $desc:expr;)*) => { - $( - #[cfg(all(feature = "cache", feature = "model", feature = "utils"))] - #[derive(Debug)] - pub enum $err { - NotPresentInCache, - $invalid_variant, - } - - #[cfg(all(feature = "cache", feature = "model", feature = "utils"))] - impl fmt::Display for $err { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.description()) } - } - - #[cfg(all(feature = "cache", feature = "model", feature = "utils"))] - impl StdError for $err { - fn description(&self) -> &str { - use self::$err::*; - - match *self { - NotPresentInCache => "not present in cache", - $invalid_variant => $desc, - } - } - } - - #[cfg(all(feature = "cache", feature = "model", feature = "utils"))] - impl FromStr for $struct { - type Err = $err; - - fn from_str(s: &str) -> StdResult<Self, Self::Err> { - match utils::$parse_fn(s) { - Some(x) => match $id(x).find() { - Some(user) => Ok(user), - _ => Err($err::NotPresentInCache), - }, - _ => Err($err::$invalid_variant), - } - } - } - )* - }; } impl_from_str! { id: @@ -187,11 +125,6 @@ impl_from_str! { id: ChannelId, ChannelIdParseError; } -impl_from_str! { struct: - Channel, ChannelId, ChannelParseError, InvalidChannel, parse_channel, "invalid channel"; - Role, RoleId, RoleParseError, InvalidRole, parse_role, "invalid role"; -} - /// A version of an emoji used only when solely the Id and name are known. #[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] pub struct EmojiIdentifier { |