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/misc.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/misc.rs')
| -rw-r--r-- | src/model/misc.rs | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/src/model/misc.rs b/src/model/misc.rs index 0d1f146..3310e4a 100644 --- a/src/model/misc.rs +++ b/src/model/misc.rs @@ -1,4 +1,5 @@ use super::*; +use internal::RwLockExt; #[cfg(all(feature = "model", feature = "utils"))] use std::result::Result as StdResult; @@ -27,9 +28,9 @@ impl Mentionable for ChannelId { impl Mentionable for Channel { fn mention(&self) -> String { match *self { - Channel::Guild(ref x) => format!("<#{}>", x.read().unwrap().id.0), - Channel::Private(ref x) => format!("<#{}>", x.read().unwrap().id.0), - Channel::Group(ref x) => format!("<#{}>", x.read().unwrap().channel_id.0), + 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)), } } } @@ -39,7 +40,7 @@ impl Mentionable for Emoji { } impl Mentionable for Member { - fn mention(&self) -> String { format!("<@{}>", self.user.read().unwrap().id.0) } + fn mention(&self) -> String { format!("<@{}>", self.user.with(|u| u.id.0)) } } impl Mentionable for RoleId { @@ -89,11 +90,9 @@ impl FromStr for User { 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)), - ) - }, + Some(x) => UserId(x as u64) + .get() + .map_err(|e| UserParseError::Rest(Box::new(e))), _ => Err(UserParseError::InvalidUsername), } } @@ -162,11 +161,9 @@ impl FromStr for Role { fn from_str(s: &str) -> StdResult<Self, Self::Err> { match utils::parse_role(s) { - Some(x) => { - match RoleId(x).find() { - Some(user) => Ok(user), - _ => Err(RoleParseError::NotPresentInCache), - } + Some(x) => match RoleId(x).find() { + Some(user) => Ok(user), + _ => Err(RoleParseError::NotPresentInCache), }, _ => Err(RoleParseError::InvalidRole), } @@ -245,11 +242,9 @@ impl FromStr for Channel { fn from_str(s: &str) -> StdResult<Self, ()> { match utils::parse_channel(s) { - Some(x) => { - match ChannelId(x).find() { - Some(channel) => Ok(channel), - _ => Err(()), - } + Some(x) => match ChannelId(x).find() { + Some(channel) => Ok(channel), + _ => Err(()), }, _ => Err(()), } |