diff options
| author | acdenisSK <[email protected]> | 2017-08-24 15:26:49 +0200 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2017-08-24 16:36:01 +0200 |
| commit | b3a5bc89ad1c09290fb1c15ca3b36fe17c3796f3 (patch) | |
| tree | 315e16f7b252d22b5f832302e722a85c9e6a9b6e /src/model/channel/mod.rs | |
| parent | Allow FromStr for User to use REST (#147) (diff) | |
| download | serenity-b3a5bc89ad1c09290fb1c15ca3b36fe17c3796f3.tar.xz serenity-b3a5bc89ad1c09290fb1c15ca3b36fe17c3796f3.zip | |
Revamp `RwLock` usage in the lib
Also not quite sure if they goofed rustfmt or something, but its changes it did were a bit bizarre.
Diffstat (limited to 'src/model/channel/mod.rs')
| -rw-r--r-- | src/model/channel/mod.rs | 59 |
1 files changed, 22 insertions, 37 deletions
diff --git a/src/model/channel/mod.rs b/src/model/channel/mod.rs index 626f466..0911139 100644 --- a/src/model/channel/mod.rs +++ b/src/model/channel/mod.rs @@ -20,6 +20,7 @@ use serde::de::Error as DeError; use serde_json; use super::utils::deserialize_u64; use model::*; +use internal::RwLockExt; #[cfg(feature = "model")] use std::fmt::{Display, Formatter, Result as FmtResult}; @@ -99,7 +100,7 @@ impl Channel { /// [`Message::delete`]: struct.Message.html#method.delete /// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html #[inline] - pub fn delete_message<M: Into<MessageId>>(&self, message_id: M) -> Result<()> { +pub fn delete_message<M: Into<MessageId>>(&self, message_id: M) -> Result<()>{ self.id().delete_message(message_id) } @@ -117,11 +118,8 @@ impl Channel { reaction_type: R) -> Result<()> where M: Into<MessageId>, R: Into<ReactionType> { - self.id().delete_reaction( - message_id, - user_id, - reaction_type, - ) + self.id() + .delete_reaction(message_id, user_id, reaction_type) } /// Edits a [`Message`] in the channel given its Id. @@ -158,9 +156,8 @@ impl Channel { #[inline] pub fn is_nsfw(&self) -> bool { match *self { - Channel::Guild(ref channel) => channel.read().unwrap().is_nsfw(), - Channel::Group(_) | - Channel::Private(_) => false, + Channel::Guild(ref channel) => channel.with(|c| c.is_nsfw()), + Channel::Group(_) | Channel::Private(_) => false, } } @@ -220,12 +217,8 @@ impl Channel { after: Option<U>) -> Result<Vec<User>> where M: Into<MessageId>, R: Into<ReactionType>, U: Into<UserId> { - self.id().reaction_users( - message_id, - reaction_type, - limit, - after, - ) + self.id() + .reaction_users(message_id, reaction_type, limit, after) } /// Retrieves the Id of the inner [`Group`], [`GuildChannel`], or @@ -236,9 +229,9 @@ impl Channel { /// [`PrivateChannel`]: struct.PrivateChannel.html pub fn id(&self) -> ChannelId { match *self { - Channel::Group(ref group) => group.read().unwrap().channel_id, - Channel::Guild(ref channel) => channel.read().unwrap().id, - Channel::Private(ref channel) => channel.read().unwrap().id, + Channel::Group(ref group) => group.with(|g| g.channel_id), + Channel::Guild(ref ch) => ch.with(|c| c.id), + Channel::Private(ref ch) => ch.with(|c| c.id), } } @@ -326,21 +319,15 @@ impl<'de> Deserialize<'de> for Channel { }; match kind { - 0 | 2 => { - serde_json::from_value::<GuildChannel>(Value::Object(v)) - .map(|x| Channel::Guild(Arc::new(RwLock::new(x)))) - .map_err(DeError::custom) - }, - 1 => { - serde_json::from_value::<PrivateChannel>(Value::Object(v)) - .map(|x| Channel::Private(Arc::new(RwLock::new(x)))) - .map_err(DeError::custom) - }, - 3 => { - serde_json::from_value::<Group>(Value::Object(v)) - .map(|x| Channel::Group(Arc::new(RwLock::new(x)))) - .map_err(DeError::custom) - }, + 0 | 2 => serde_json::from_value::<GuildChannel>(Value::Object(v)) + .map(|x| Channel::Guild(Arc::new(RwLock::new(x)))) + .map_err(DeError::custom), + 1 => serde_json::from_value::<PrivateChannel>(Value::Object(v)) + .map(|x| Channel::Private(Arc::new(RwLock::new(x)))) + .map_err(DeError::custom), + 3 => serde_json::from_value::<Group>(Value::Object(v)) + .map(|x| Channel::Group(Arc::new(RwLock::new(x)))) + .map_err(DeError::custom), _ => Err(DeError::custom("Unknown channel type")), } } @@ -412,10 +399,8 @@ impl ChannelType { struct PermissionOverwriteData { allow: Permissions, deny: Permissions, - #[serde(deserialize_with = "deserialize_u64")] - id: u64, - #[serde(rename = "type")] - kind: String, + #[serde(deserialize_with = "deserialize_u64")] id: u64, + #[serde(rename = "type")] kind: String, } /// A channel-specific permission overwrite for a member or role. |