diff options
| author | acdenisSK <[email protected]> | 2017-07-27 06:42:48 +0200 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2017-07-27 07:30:23 +0200 |
| commit | 550030264952f0e0043b63f4582bb817ef8bbf37 (patch) | |
| tree | b921e2f78fd603a5ca671623083a32806fd16090 /src/model/channel/channel_id.rs | |
| parent | Use a consistent indentation style (diff) | |
| download | serenity-550030264952f0e0043b63f4582bb817ef8bbf37.tar.xz serenity-550030264952f0e0043b63f4582bb817ef8bbf37.zip | |
rustfmt
Diffstat (limited to 'src/model/channel/channel_id.rs')
| -rw-r--r-- | src/model/channel/channel_id.rs | 167 |
1 files changed, 81 insertions, 86 deletions
diff --git a/src/model/channel/channel_id.rs b/src/model/channel/channel_id.rs index f83062c..62d8820 100644 --- a/src/model/channel/channel_id.rs +++ b/src/model/channel/channel_id.rs @@ -1,18 +1,18 @@ use std::fmt::{Display, Formatter, Result as FmtResult}; -use ::model::*; +use model::*; -#[cfg(feature="model")] +#[cfg(feature = "model")] use std::borrow::Cow; -#[cfg(feature="model")] +#[cfg(feature = "model")] use std::fmt::Write as FmtWrite; -#[cfg(feature="model")] -use ::builder::{CreateMessage, EditChannel, GetMessages}; -#[cfg(feature="cache")] -use ::CACHE; -#[cfg(feature="model")] -use ::http::{self, AttachmentType}; - -#[cfg(feature="model")] +#[cfg(feature = "model")] +use builder::{CreateMessage, EditChannel, GetMessages}; +#[cfg(feature = "cache")] +use CACHE; +#[cfg(feature = "model")] +use http::{self, AttachmentType}; + +#[cfg(feature = "model")] impl ChannelId { /// Broadcasts that the current user is typing to a channel for the next 5 /// seconds. @@ -35,9 +35,7 @@ impl ChannelId { /// /// [Send Messages]: permissions/constant.SEND_MESSAGES.html #[inline] - pub fn broadcast_typing(&self) -> Result<()> { - http::broadcast_typing(self.0) - } + pub fn broadcast_typing(&self) -> Result<()> { http::broadcast_typing(self.0) } /// Creates a [permission overwrite][`PermissionOverwrite`] for either a /// single [`Member`] or [`Role`] within the channel. @@ -52,8 +50,7 @@ impl ChannelId { /// [`PermissionOverwrite`]: struct.PermissionOverwrite.html /// [`Role`]: struct.Role.html /// [Manage Channels]: permissions/constant.MANAGE_CHANNELS.html - pub fn create_permission(&self, target: &PermissionOverwrite) - -> Result<()> { + pub fn create_permission(&self, target: &PermissionOverwrite) -> Result<()> { let (id, kind) = match target.kind { PermissionOverwriteType::Member(id) => (id.0, "member"), PermissionOverwriteType::Role(id) => (id.0, "role"), @@ -82,16 +79,16 @@ impl ChannelId { /// [`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>, { http::create_reaction(self.0, message_id.into().0, &reaction_type.into()) } /// Deletes this channel, returning the channel on a successful deletion. #[inline] - pub fn delete(&self) -> Result<Channel> { - http::delete_channel(self.0) - } + pub fn delete(&self) -> Result<Channel> { http::delete_channel(self.0) } /// Deletes a [`Message`] given its Id. /// @@ -123,7 +120,8 @@ impl ChannelId { /// [`Channel::delete_messages`]: enum.Channel.html#method.delete_messages /// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html pub fn delete_messages(&self, message_ids: &[MessageId]) -> Result<()> { - let ids = message_ids.into_iter() + let ids = message_ids + .into_iter() .map(|message_id| message_id.0) .collect::<Vec<u64>>(); @@ -153,8 +151,14 @@ impl ChannelId { /// /// [`Reaction`]: struct.Reaction.html /// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html - 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> { + 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>, { http::delete_reaction(self.0, message_id.into().0, user_id.map(|uid| uid.0), @@ -205,7 +209,9 @@ impl ChannelId { /// [`Message`]: struct.Message.html /// [`the limit`]: ../builder/struct.CreateMessage.html#method.content 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>, { let map = f(CreateMessage::default()).0; if let Some(content) = map.get("content") { @@ -220,15 +226,13 @@ impl ChannelId { } /// Search the cache for the channel with the Id. - #[cfg(feature="cache")] - pub fn find(&self) -> Option<Channel> { - CACHE.read().unwrap().channel(*self) - } + #[cfg(feature = "cache")] + pub fn find(&self) -> Option<Channel> { CACHE.read().unwrap().channel(*self) } /// Search the cache for the channel. If it can't be found, the channel is /// requested over REST. pub fn get(&self) -> Result<Channel> { - #[cfg(feature="cache")] + #[cfg(feature = "cache")] { if let Some(channel) = CACHE.read().unwrap().channel(*self) { return Ok(channel); @@ -243,9 +247,7 @@ impl ChannelId { /// Requires the [Manage Channels] permission. /// [Manage Channels]: permissions/constant.MANAGE_CHANNELS.html #[inline] - pub fn invites(&self) -> Result<Vec<RichInvite>> { - http::get_channel_invites(self.0) - } + pub fn invites(&self) -> Result<Vec<RichInvite>> { http::get_channel_invites(self.0) } /// Gets a message from the channel. /// @@ -254,12 +256,11 @@ impl ChannelId { /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html #[inline] pub fn message<M: Into<MessageId>>(&self, message_id: M) -> Result<Message> { - http::get_message(self.0, message_id.into().0) - .map(|mut msg| { - msg.transform_content(); + http::get_message(self.0, message_id.into().0).map(|mut msg| { + msg.transform_content(); - msg - }) + msg + }) } /// Gets messages from the channel. @@ -271,7 +272,8 @@ impl ChannelId { /// [`Channel::messages`]: enum.Channel.html#method.messages /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html pub fn messages<F>(&self, f: F) -> Result<Vec<Message>> - where F: FnOnce(GetMessages) -> GetMessages { + where + F: FnOnce(GetMessages) -> GetMessages, { let mut map = f(GetMessages::default()).0; let mut query = format!("?limit={}", map.remove("limit").unwrap_or(50)); @@ -283,35 +285,35 @@ impl ChannelId { write!(query, "&before={}", before)?; } - http::get_messages(self.0, &query) - .map(|msgs| msgs - .into_iter() + http::get_messages(self.0, &query).map(|msgs| { + msgs.into_iter() .map(|mut msg| { msg.transform_content(); msg - }).collect::<Vec<Message>>()) + }) + .collect::<Vec<Message>>() + }) } /// Returns the name of whatever channel this id holds. - #[cfg(feature="model")] + #[cfg(feature = "model")] pub fn name(&self) -> Option<String> { use self::Channel::*; - Some(match match self.find() { Some(c) => c, None => return None, } { - Guild(channel) => { - channel.read().unwrap().name().to_string() - }, - Group(channel) => { - match channel.read().unwrap().name() { - Cow::Borrowed(name) => name.to_string(), - Cow::Owned(name) => name, - } - }, - Private(channel) => { - channel.read().unwrap().name() - } - }) + Some(match match self.find() { + Some(c) => c, + None => return None, + } { + Guild(channel) => channel.read().unwrap().name().to_string(), + Group(channel) => { + match channel.read().unwrap().name() { + Cow::Borrowed(name) => name.to_string(), + Cow::Owned(name) => name, + } + }, + Private(channel) => channel.read().unwrap().name(), + }) } /// Pins a [`Message`] to the channel. @@ -326,9 +328,7 @@ impl ChannelId { /// /// [`Message`]: struct.Message.html #[inline] - pub fn pins(&self) -> Result<Vec<Message>> { - http::get_pins(self.0) - } + pub fn pins(&self) -> Result<Vec<Message>> { http::get_pins(self.0) } /// Gets the list of [`User`]s who have reacted to a [`Message`] with a /// certain [`Emoji`]. @@ -343,11 +343,15 @@ impl ChannelId { /// [`User`]: struct.User.html /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html pub fn reaction_users<M, R, U>(&self, - message_id: M, - reaction_type: R, - limit: Option<u8>, - after: Option<U>) - -> Result<Vec<User>> where M: Into<MessageId>, R: Into<ReactionType>, U: Into<UserId> { + message_id: M, + reaction_type: R, + limit: Option<u8>, + after: Option<U>) + -> Result<Vec<User>> + where + M: Into<MessageId>, + R: Into<ReactionType>, + U: Into<UserId>, { let limit = limit.map_or(50, |x| if x > 100 { 100 } else { x }); http::get_reaction_users(self.0, @@ -432,7 +436,9 @@ impl ChannelId { /// [Attach Files]: permissions/constant.ATTACH_FILES.html /// [Send Messages]: permissions/constant.SEND_MESSAGES.html 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>>, { let mut map = f(CreateMessage::default()).0; if let Some(content) = map.get("content") { @@ -468,7 +474,8 @@ impl ChannelId { /// [`CreateMessage`]: ../builder/struct.CreateMessage.html /// [Send Messages]: permissions/constant.SEND_MESSAGES.html pub fn send_message<F>(&self, f: F) -> Result<Message> - where F: FnOnce(CreateMessage) -> CreateMessage { + where + F: FnOnce(CreateMessage) -> CreateMessage, { let CreateMessage(map, reactions) = f(CreateMessage::default()); Message::check_content_length(&map)?; @@ -502,9 +509,7 @@ impl ChannelId { /// /// [Manage Webhooks]: permissions/constant.MANAGE_WEBHOOKS.html #[inline] - pub fn webhooks(&self) -> Result<Vec<Webhook>> { - http::get_channel_webhooks(self.0) - } + pub fn webhooks(&self) -> Result<Vec<Webhook>> { http::get_channel_webhooks(self.0) } } impl From<Channel> for ChannelId { @@ -531,33 +536,23 @@ impl<'a> From<&'a Channel> for ChannelId { impl From<PrivateChannel> for ChannelId { /// Gets the Id of a private channel. - fn from(private_channel: PrivateChannel) -> ChannelId { - private_channel.id - } + fn from(private_channel: PrivateChannel) -> ChannelId { private_channel.id } } impl<'a> From<&'a PrivateChannel> for ChannelId { /// Gets the Id of a private channel. - fn from(private_channel: &PrivateChannel) -> ChannelId { - private_channel.id - } + fn from(private_channel: &PrivateChannel) -> ChannelId { private_channel.id } } impl From<GuildChannel> for ChannelId { /// Gets the Id of a guild channel. - fn from(public_channel: GuildChannel) -> ChannelId { - public_channel.id - } + fn from(public_channel: GuildChannel) -> ChannelId { public_channel.id } } impl<'a> From<&'a GuildChannel> for ChannelId { /// Gets the Id of a guild channel. - fn from(public_channel: &GuildChannel) -> ChannelId { - public_channel.id - } + fn from(public_channel: &GuildChannel) -> ChannelId { public_channel.id } } impl Display for ChannelId { - fn fmt(&self, f: &mut Formatter) -> FmtResult { - Display::fmt(&self.0, f) - } + fn fmt(&self, f: &mut Formatter) -> FmtResult { Display::fmt(&self.0, f) } } |