aboutsummaryrefslogtreecommitdiff
path: root/src/model/channel/mod.rs
diff options
context:
space:
mode:
authoracdenisSK <[email protected]>2017-07-27 06:42:48 +0200
committeracdenisSK <[email protected]>2017-07-27 07:30:23 +0200
commit550030264952f0e0043b63f4582bb817ef8bbf37 (patch)
treeb921e2f78fd603a5ca671623083a32806fd16090 /src/model/channel/mod.rs
parentUse a consistent indentation style (diff)
downloadserenity-550030264952f0e0043b63f4582bb817ef8bbf37.tar.xz
serenity-550030264952f0e0043b63f4582bb817ef8bbf37.zip
rustfmt
Diffstat (limited to 'src/model/channel/mod.rs')
-rw-r--r--src/model/channel/mod.rs111
1 files changed, 66 insertions, 45 deletions
diff --git a/src/model/channel/mod.rs b/src/model/channel/mod.rs
index 708e276..02be9d8 100644
--- a/src/model/channel/mod.rs
+++ b/src/model/channel/mod.rs
@@ -19,14 +19,14 @@ pub use self::reaction::*;
use serde::de::Error as DeError;
use serde_json;
use super::utils::deserialize_u64;
-use ::model::*;
+use model::*;
-#[cfg(feature="model")]
+#[cfg(feature = "model")]
use std::fmt::{Display, Formatter, Result as FmtResult};
-#[cfg(feature="model")]
-use ::builder::{CreateMessage, GetMessages};
-#[cfg(feature="model")]
-use ::http::AttachmentType;
+#[cfg(feature = "model")]
+use builder::{CreateMessage, GetMessages};
+#[cfg(feature = "model")]
+use http::AttachmentType;
/// A container for any channel.
#[derive(Clone, Debug)]
@@ -46,7 +46,7 @@ pub enum Channel {
Private(Arc<RwLock<PrivateChannel>>),
}
-#[cfg(feature="model")]
+#[cfg(feature = "model")]
impl Channel {
/// React to a [`Message`] with a custom [`Emoji`] or unicode character.
///
@@ -61,8 +61,10 @@ impl Channel {
/// [`Message::react`]: struct.Message.html#method.react
/// [Add Reactions]: permissions/constant.ADD_REACTIONS.html
#[inline]
- pub fn create_reaction<M, R>(&self, message_id: M, reaction_type: R)
- -> Result<()> where M: Into<MessageId>, R: Into<ReactionType> {
+ pub fn create_reaction<M, R>(&self, message_id: M, reaction_type: R) -> Result<()>
+ where
+ M: Into<MessageId>,
+ R: Into<ReactionType>, {
self.id().create_reaction(message_id, reaction_type)
}
@@ -111,9 +113,16 @@ impl Channel {
/// [`Reaction`]: struct.Reaction.html
/// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html
#[inline]
- pub fn delete_reaction<M, R>(&self, message_id: M, user_id: Option<UserId>, reaction_type: R)
- -> Result<()> where M: Into<MessageId>, R: Into<ReactionType> {
- self.id().delete_reaction(message_id, user_id, reaction_type)
+ pub fn delete_reaction<M, R>(&self,
+ message_id: M,
+ user_id: Option<UserId>,
+ reaction_type: R)
+ -> Result<()>
+ where
+ M: Into<MessageId>,
+ R: Into<ReactionType>, {
+ self.id()
+ .delete_reaction(message_id, user_id, reaction_type)
}
/// Edits a [`Message`] in the channel given its Id.
@@ -137,7 +146,9 @@ impl Channel {
/// [`the limit`]: ../builder/struct.CreateMessage.html#method.content
#[inline]
pub fn edit_message<F, M>(&self, message_id: M, f: F) -> Result<Message>
- where F: FnOnce(CreateMessage) -> CreateMessage, M: Into<MessageId> {
+ where
+ F: FnOnce(CreateMessage) -> CreateMessage,
+ M: Into<MessageId>, {
self.id().edit_message(message_id, f)
}
@@ -146,7 +157,7 @@ impl Channel {
/// Refer to [`utils::is_nsfw`] for more details.
///
/// [`utils::is_nsfw`]: ../utils/fn.is_nsfw.html
- #[cfg(feature="utils")]
+ #[cfg(feature = "utils")]
#[inline]
pub fn is_nsfw(&self) -> bool {
match *self {
@@ -183,7 +194,8 @@ impl Channel {
/// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html
#[inline]
pub fn messages<F>(&self, f: F) -> Result<Vec<Message>>
- where F: FnOnce(GetMessages) -> GetMessages {
+ where
+ F: FnOnce(GetMessages) -> GetMessages, {
self.id().messages(f)
}
@@ -209,8 +221,13 @@ impl Channel {
reaction_type: R,
limit: Option<u8>,
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)
+ -> Result<Vec<User>>
+ where
+ M: Into<MessageId>,
+ R: Into<ReactionType>,
+ U: Into<UserId>, {
+ self.id()
+ .reaction_users(message_id, reaction_type, limit, after)
}
/// Retrieves the Id of the inner [`Group`], [`GuildChannel`], or
@@ -238,9 +255,7 @@ impl Channel {
/// [`ChannelId`]: struct.ChannelId.html
/// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong
#[inline]
- pub fn say(&self, content: &str) -> Result<Message> {
- self.id().say(content)
- }
+ pub fn say(&self, content: &str) -> Result<Message> { self.id().say(content) }
/// Sends (a) file(s) along with optional message contents.
///
@@ -262,7 +277,9 @@ impl Channel {
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
#[inline]
pub fn send_files<'a, F, T>(&self, files: Vec<T>, f: F) -> Result<Message>
- where F: FnOnce(CreateMessage) -> CreateMessage, T: Into<AttachmentType<'a>> {
+ where
+ F: FnOnce(CreateMessage) -> CreateMessage,
+ T: Into<AttachmentType<'a>>, {
self.id().send_files(files, f)
}
@@ -287,7 +304,8 @@ impl Channel {
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
#[inline]
pub fn send_message<F>(&self, f: F) -> Result<Message>
- where F: FnOnce(CreateMessage) -> CreateMessage {
+ where
+ F: FnOnce(CreateMessage) -> CreateMessage, {
self.id().send_message(f)
}
@@ -313,21 +331,27 @@ 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")),
}
}
}
-#[cfg(feature="model")]
+#[cfg(feature = "model")]
impl Display for Channel {
/// Formats the channel into a "mentioned" string.
///
@@ -344,12 +368,8 @@ impl Display for Channel {
/// [`PrivateChannel`]: struct.PrivateChannel.html
fn fmt(&self, f: &mut Formatter) -> FmtResult {
match *self {
- Channel::Group(ref group) => {
- Display::fmt(&group.read().unwrap().name(), f)
- },
- Channel::Guild(ref ch) => {
- Display::fmt(&ch.read().unwrap().id.mention(), f)
- },
+ Channel::Group(ref group) => Display::fmt(&group.read().unwrap().name(), f),
+ Channel::Guild(ref ch) => Display::fmt(&ch.read().unwrap().id.mention(), f),
Channel::Private(ref ch) => {
let channel = ch.read().unwrap();
let recipient = channel.recipient.read().unwrap();
@@ -397,9 +417,9 @@ impl ChannelType {
struct PermissionOverwriteData {
allow: Permissions,
deny: Permissions,
- #[serde(deserialize_with="deserialize_u64")]
+ #[serde(deserialize_with = "deserialize_u64")]
id: u64,
- #[serde(rename="type")]
+ #[serde(rename = "type")]
kind: String,
}
@@ -412,7 +432,8 @@ pub struct PermissionOverwrite {
}
impl<'de> Deserialize<'de> for PermissionOverwrite {
- fn deserialize<D: Deserializer<'de>>(deserializer: D) -> StdResult<PermissionOverwrite, D::Error> {
+ fn deserialize<D: Deserializer<'de>>(deserializer: D)
+ -> StdResult<PermissionOverwrite, D::Error> {
let data = PermissionOverwriteData::deserialize(deserializer)?;
let kind = match &data.kind[..] {
@@ -422,10 +443,10 @@ impl<'de> Deserialize<'de> for PermissionOverwrite {
};
Ok(PermissionOverwrite {
- allow: data.allow,
- deny: data.deny,
- kind: kind,
- })
+ allow: data.allow,
+ deny: data.deny,
+ kind: kind,
+ })
}
}