diff options
| author | Austin Hellyer <[email protected]> | 2017-01-08 08:45:17 -0800 |
|---|---|---|
| committer | Austin Hellyer <[email protected]> | 2017-01-08 08:45:17 -0800 |
| commit | a658105f7499efe994280906e85fd51c2b70c3a7 (patch) | |
| tree | 4c8af6a353b9fece3f5a9d9a9e7a90f25d53cc79 /src | |
| parent | Wait 5s between shard boots (diff) | |
| download | serenity-a658105f7499efe994280906e85fd51c2b70c3a7.tar.xz serenity-a658105f7499efe994280906e85fd51c2b70c3a7.zip | |
Code style cleanup
Diffstat (limited to 'src')
| -rw-r--r-- | src/constants.rs | 46 | ||||
| -rw-r--r-- | src/ext/cache/mod.rs | 2 | ||||
| -rw-r--r-- | src/lib.rs | 2 | ||||
| -rw-r--r-- | src/model/channel.rs | 8 | ||||
| -rw-r--r-- | src/model/event.rs | 88 | ||||
| -rw-r--r-- | src/model/guild.rs | 6 | ||||
| -rw-r--r-- | src/model/misc.rs | 7 | ||||
| -rw-r--r-- | src/model/user.rs | 1 | ||||
| -rw-r--r-- | src/model/utils.rs | 13 |
9 files changed, 68 insertions, 105 deletions
diff --git a/src/constants.rs b/src/constants.rs index cf3cf0b..98c15eb 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -54,52 +54,6 @@ pub enum ErrorCode { UnknownUser, } -/* -map_nums! { ErrorCode; - BotsCannotUse 20001, - CannotSendEmptyMessage 50006, - CannotSendMessagesInVoice 50008, - CannotSendMessagesToUser 50007, - ChannelVerificationTooHigh 50009, - EditByOtherAuthor 50005, - EmbedDisabled 50004, - InvalidAccountType 50002, - InvalidAuthToken 50014, - InvalidBulkDeleteCount 50016, - InvalidDMChannelAction 50003, - InvalidOauthState 50012, - InvalidPinChannel 50019, - MaxFriendsReached 30002, - MaxGuildsReached 30001, - MaxPinsReached 30003, - MaxRolesReached 30005, - MissingAccess 50001, - MissingPermissions 500013, - NoteTooLong 50015, - Oauth2ApplicationLacksBot 50010, - Oauth2ApplicationLimitReached 50011, - OnlyBotsCanUse 20002, - ReactionBlocked 90001, - SearchIndexUnavailable 110000, - TooManyReactions 30010, - Unauthorized 40001, - UnknownAccount 10001, - UnknownApplication 10002, - UnknownChannel 10003, - UnknownEmoji 10014, - UnknownGuild 10004, - UnknownIntegration 10005, - UnknownInvite 10006, - UnknownMember 10007, - UnknownMessage 10008, - UnknownOverwrite 10009, - UnknownProvider 10010, - UnknownRole 10011, - UnknownToken 10012, - UnknownUser 10013, -} -*/ - #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum OpCode { Event, diff --git a/src/ext/cache/mod.rs b/src/ext/cache/mod.rs index 7d6255e..6d68bf9 100644 --- a/src/ext/cache/mod.rs +++ b/src/ext/cache/mod.rs @@ -114,7 +114,7 @@ use ::model::event::*; /// [`Guild`]: ../../model/struct.Guild.html /// [`Role`]: ../../model/struct.Role.html /// [`rest`]: ../../client/rest/index.html -#[derive(Debug, Clone)] +#[derive(Clone, Debug)] pub struct Cache { /// A map of the currently active calls that the current user knows about, /// where the key is the Id of the [`PrivateChannel`] or [`Group`] hosting @@ -144,7 +144,7 @@ //! [examples]: https://github.com/zeyla/serenity/tree/master/examples //! [gateway docs]: client/gateway/index.html #![allow(doc_markdown, inline_always, unknown_lints)] -#![doc(html_logo_url = "https://docs.austinhellyer.me/serenity/docs_header.png")] +#![doc(html_logo_url="https://docs.austinhellyer.me/serenity/docs_header.png")] #![warn(enum_glob_use, if_not_else)] #[macro_use] diff --git a/src/model/channel.rs b/src/model/channel.rs index 6e9f020..20b2be7 100644 --- a/src/model/channel.rs +++ b/src/model/channel.rs @@ -260,7 +260,7 @@ impl Channel { /// [`ClientError::InvalidOperationAsBot`]: ../client/enum.ClientError.html#variant.InvalidOperationAsBot /// [`Message`]: struct.Message.html /// [`Search`]: ../utils/builder/struct.Search.html - #[cfg(feature = "methods")] + #[cfg(feature="methods")] pub fn search<F>(&self, f: F) -> Result<SearchResult> where F: FnOnce(Search) -> Search { #[cfg(feature="cache")] @@ -451,7 +451,7 @@ impl Group { /// [`ClientError::InvalidOperationAsBot`]: ../client/enum.ClientError.html#variant.InvalidOperationAsBot /// [`Message`]: struct.Message.html /// [`Search`]: ../utils/builder/struct.Search.html - #[cfg(feature = "methods")] + #[cfg(feature="methods")] pub fn search<F>(&self, f: F) -> Result<SearchResult> where F: FnOnce(Search) -> Search { rest::search_channel_messages(self.channel_id.0, f(Search::default()).0) @@ -904,7 +904,7 @@ impl PrivateChannel { /// [`ClientError::InvalidOperationAsBot`]: ../client/enum.ClientError.html#variant.InvalidOperationAsBot /// [`Message`]: struct.Message.html /// [`Search`]: ../utils/builder/struct.Search.html - #[cfg(feature = "methods")] + #[cfg(feature="methods")] pub fn search<F>(&self, f: F) -> Result<SearchResult> where F: FnOnce(Search) -> Search { #[cfg(feature="cache")] @@ -1114,7 +1114,7 @@ impl GuildChannel { /// [`ClientError::InvalidOperationAsBot`]: ../client/enum.ClientError.html#variant.InvalidOperationAsBot /// [`Message`]: struct.Message.html /// [`Search`]: ../utils/builder/struct.Search.html - #[cfg(feature = "methods")] + #[cfg(feature="methods")] pub fn search<F>(&self, f: F) -> Result<SearchResult> where F: FnOnce(Search) -> Search { #[cfg(feature="cache")] diff --git a/src/model/event.rs b/src/model/event.rs index 754a9b2..2831d2b 100644 --- a/src/model/event.rs +++ b/src/model/event.rs @@ -102,8 +102,8 @@ impl ChannelPinsAckEvent { #[inline] pub fn decode(mut map: Map) -> Result<Self> { Ok(ChannelPinsAckEvent { - channel_id: remove(&mut map, "channel_id").and_then(ChannelId::decode)?, - timestamp: remove(&mut map, "timestamp").and_then(into_string)?, + channel_id: remove(&mut map, "channel_id").and_then(ChannelId::decode)?, + timestamp: remove(&mut map, "timestamp").and_then(into_string)?, }) } } @@ -119,8 +119,8 @@ impl ChannelPinsUpdateEvent { #[inline] pub fn decode(mut map: Map) -> Result<Self> { Ok(ChannelPinsUpdateEvent { - channel_id: remove(&mut map, "channel_id").and_then(ChannelId::decode)?, - last_pin_timestamp: opt(&mut map, "last_pin_timestamp", into_string)?, + channel_id: remove(&mut map, "channel_id").and_then(ChannelId::decode)?, + last_pin_timestamp: opt(&mut map, "last_pin_timestamp", into_string)?, }) } } @@ -136,8 +136,8 @@ impl ChannelRecipientAddEvent { #[inline] pub fn decode(mut map: Map) -> Result<Self> { Ok(ChannelRecipientAddEvent { - channel_id: remove(&mut map, "channel_id").and_then(ChannelId::decode)?, - user: remove(&mut map, "user").and_then(User::decode)?, + channel_id: remove(&mut map, "channel_id").and_then(ChannelId::decode)?, + user: remove(&mut map, "user").and_then(User::decode)?, }) } } @@ -153,8 +153,8 @@ impl ChannelRecipientRemoveEvent { #[inline] pub fn decode(mut map: Map) -> Result<Self> { Ok(ChannelRecipientRemoveEvent { - channel_id: remove(&mut map, "channel_id").and_then(ChannelId::decode)?, - user: remove(&mut map, "user").and_then(User::decode)?, + channel_id: remove(&mut map, "channel_id").and_then(ChannelId::decode)?, + user: remove(&mut map, "user").and_then(User::decode)?, }) } } @@ -169,7 +169,7 @@ impl ChannelUpdateEvent { #[inline] pub fn decode(map: Map) -> Result<Self> { Ok(ChannelUpdateEvent { - channel: Channel::decode(Value::Object(map))?, + channel: Channel::decode(Value::Object(map))?, }) } } @@ -185,8 +185,8 @@ impl FriendSuggestionCreateEvent { #[inline] pub fn decode(mut map: Map) -> Result<Self> { Ok(FriendSuggestionCreateEvent { - reasons: decode_array(remove(&mut map, "reasons")?, SuggestionReason::decode)?, - suggested_user: remove(&mut map, "suggested_user").and_then(User::decode)?, + reasons: decode_array(remove(&mut map, "reasons")?, SuggestionReason::decode)?, + suggested_user: remove(&mut map, "suggested_user").and_then(User::decode)?, }) } } @@ -201,7 +201,7 @@ impl FriendSuggestionDeleteEvent { #[inline] pub fn decode(mut map: Map) -> Result<Self> { Ok(FriendSuggestionDeleteEvent { - suggested_user_id: remove(&mut map, "suggested_user_id").and_then(UserId::decode)?, + suggested_user_id: remove(&mut map, "suggested_user_id").and_then(UserId::decode)?, }) } } @@ -217,8 +217,8 @@ impl GuildBanAddEvent { #[inline] pub fn decode(mut map: Map) -> Result<Self> { Ok(GuildBanAddEvent { - guild_id: remove(&mut map, "guild_id").and_then(GuildId::decode)?, - user: remove(&mut map, "user").and_then(User::decode)?, + guild_id: remove(&mut map, "guild_id").and_then(GuildId::decode)?, + user: remove(&mut map, "user").and_then(User::decode)?, }) } } @@ -234,8 +234,8 @@ impl GuildBanRemoveEvent { #[inline] pub fn decode(mut map: Map) -> Result<Self> { Ok(GuildBanRemoveEvent { - guild_id: remove(&mut map, "guild_id").and_then(GuildId::decode)?, - user: remove(&mut map, "user").and_then(User::decode)?, + guild_id: remove(&mut map, "guild_id").and_then(GuildId::decode)?, + user: remove(&mut map, "user").and_then(User::decode)?, }) } } @@ -281,8 +281,8 @@ impl GuildEmojisUpdateEvent { #[inline] pub fn decode(mut map: Map) -> Result<Self> { Ok(GuildEmojisUpdateEvent { - emojis: remove(&mut map, "emojis").and_then(decode_emojis)?, - guild_id: remove(&mut map, "guild_id").and_then(GuildId::decode)?, + emojis: remove(&mut map, "emojis").and_then(decode_emojis)?, + guild_id: remove(&mut map, "guild_id").and_then(GuildId::decode)?, }) } } @@ -297,7 +297,7 @@ impl GuildIntegrationsUpdateEvent { #[inline] pub fn decode(mut map: Map) -> Result<Self> { Ok(GuildIntegrationsUpdateEvent { - guild_id: remove(&mut map, "guild_id").and_then(GuildId::decode)?, + guild_id: remove(&mut map, "guild_id").and_then(GuildId::decode)?, }) } } @@ -313,8 +313,8 @@ impl GuildMemberAddEvent { #[inline] pub fn decode(mut map: Map) -> Result<Self> { Ok(GuildMemberAddEvent { - guild_id: remove(&mut map, "guild_id").and_then(GuildId::decode)?, - member: Member::decode(Value::Object(map))?, + guild_id: remove(&mut map, "guild_id").and_then(GuildId::decode)?, + member: Member::decode(Value::Object(map))?, }) } } @@ -330,8 +330,8 @@ impl GuildMemberRemoveEvent { #[inline] pub fn decode(mut map: Map) -> Result<Self> { Ok(GuildMemberRemoveEvent { - guild_id: remove(&mut map, "guild_id").and_then(GuildId::decode)?, - user: remove(&mut map, "user").and_then(User::decode)?, + guild_id: remove(&mut map, "guild_id").and_then(GuildId::decode)?, + user: remove(&mut map, "user").and_then(User::decode)?, }) } } @@ -349,10 +349,10 @@ impl GuildMemberUpdateEvent { #[inline] pub fn decode(mut map: Map) -> Result<Self> { Ok(GuildMemberUpdateEvent { - guild_id: remove(&mut map, "guild_id").and_then(GuildId::decode)?, - nick: opt(&mut map, "nick", into_string)?, - roles: decode_array(remove(&mut map, "roles")?, RoleId::decode)?, - user: remove(&mut map, "user").and_then(User::decode)?, + guild_id: remove(&mut map, "guild_id").and_then(GuildId::decode)?, + nick: opt(&mut map, "nick", into_string)?, + roles: decode_array(remove(&mut map, "roles")?, RoleId::decode)?, + user: remove(&mut map, "user").and_then(User::decode)?, }) } } @@ -368,8 +368,8 @@ impl GuildMembersChunkEvent { #[inline] pub fn decode(mut map: Map) -> Result<Self> { Ok(GuildMembersChunkEvent { - guild_id: remove(&mut map, "guild_id").and_then(GuildId::decode)?, - members: remove(&mut map, "members").and_then(decode_members)?, + guild_id: remove(&mut map, "guild_id").and_then(GuildId::decode)?, + members: remove(&mut map, "members").and_then(decode_members)?, }) } } @@ -385,8 +385,8 @@ impl GuildRoleCreateEvent { #[inline] pub fn decode(mut map: Map) -> Result<Self> { Ok(GuildRoleCreateEvent { - guild_id: remove(&mut map, "guild_id").and_then(GuildId::decode)?, - role: remove(&mut map, "role").and_then(Role::decode)?, + guild_id: remove(&mut map, "guild_id").and_then(GuildId::decode)?, + role: remove(&mut map, "role").and_then(Role::decode)?, }) } } @@ -402,8 +402,8 @@ impl GuildRoleDeleteEvent { #[inline] pub fn decode(mut map: Map) -> Result<Self> { Ok(GuildRoleDeleteEvent { - guild_id: remove(&mut map, "guild_id").and_then(GuildId::decode)?, - role_id: remove(&mut map, "role_id").and_then(RoleId::decode)?, + guild_id: remove(&mut map, "guild_id").and_then(GuildId::decode)?, + role_id: remove(&mut map, "role_id").and_then(RoleId::decode)?, }) } } @@ -419,8 +419,8 @@ impl GuildRoleUpdateEvent { #[inline] pub fn decode(mut map: Map) -> Result<Self> { Ok(GuildRoleUpdateEvent { - guild_id: remove(&mut map, "guild_id").and_then(GuildId::decode)?, - role: remove(&mut map, "role").and_then(Role::decode)?, + guild_id: remove(&mut map, "guild_id").and_then(GuildId::decode)?, + role: remove(&mut map, "role").and_then(Role::decode)?, }) } } @@ -438,10 +438,10 @@ impl GuildSyncEvent { #[inline] pub fn decode(mut map: Map) -> Result<Self> { Ok(GuildSyncEvent { - guild_id: remove(&mut map, "id").and_then(GuildId::decode)?, - large: req!(remove(&mut map, "large")?.as_bool()), - members: remove(&mut map, "members").and_then(decode_members)?, - presences: remove(&mut map, "presences").and_then(decode_presences)?, + guild_id: remove(&mut map, "id").and_then(GuildId::decode)?, + large: req!(remove(&mut map, "large")?.as_bool()), + members: remove(&mut map, "members").and_then(decode_members)?, + presences: remove(&mut map, "presences").and_then(decode_presences)?, }) } } @@ -471,7 +471,7 @@ impl GuildUpdateEvent { #[inline] pub fn decode(map: Map) -> Result<Self> { Ok(GuildUpdateEvent { - guild: PartialGuild::decode(Value::Object(map))?, + guild: PartialGuild::decode(Value::Object(map))?, }) } } @@ -488,8 +488,8 @@ impl MessageAckEvent { #[inline] pub fn decode(mut map: Map) -> Result<Self> { Ok(MessageAckEvent { - channel_id: remove(&mut map, "channel_id").and_then(ChannelId::decode)?, - message_id: opt(&mut map, "message_id", MessageId::decode)?, + channel_id: remove(&mut map, "channel_id").and_then(ChannelId::decode)?, + message_id: opt(&mut map, "message_id", MessageId::decode)?, }) } } @@ -504,7 +504,7 @@ impl MessageCreateEvent { #[inline] pub fn decode(map: Map) -> Result<Self> { Ok(MessageCreateEvent { - message: Message::decode(Value::Object(map))?, + message: Message::decode(Value::Object(map))?, }) } } @@ -1185,7 +1185,7 @@ pub struct VoiceSpeaking { } impl VoiceSpeaking { - #[doc(hdiden)] + #[doc(hidden)] #[inline] pub fn decode(mut map: Map) -> Result<Self> { Ok(VoiceSpeaking { diff --git a/src/model/guild.rs b/src/model/guild.rs index 80760b7..5945598 100644 --- a/src/model/guild.rs +++ b/src/model/guild.rs @@ -203,7 +203,7 @@ impl PartialGuild { /// [`Search`]: ../utils/builder/struct.Search.html /// [`search_channels`]: #method.search_channels /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html - #[cfg(feature = "methods")] + #[cfg(feature="methods")] pub fn search<F>(&self, f: F) -> Result<SearchResult> where F: FnOnce(Search) -> Search { #[cfg(feature="cache")] @@ -241,7 +241,7 @@ impl PartialGuild { /// [`Search`]: ../utils/builder/struct.Search.html /// [`search`]: #method.search /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html - #[cfg(feature = "methods")] + #[cfg(feature="methods")] pub fn search_channels<F>(&self, channel_ids: &[ChannelId], f: F) -> Result<SearchResult> where F: FnOnce(Search) -> Search { #[cfg(feature="cache")] @@ -857,7 +857,7 @@ impl Guild { /// [`Search`]: ../utils/builder/struct.Search.html /// [`search_channels`]: #method.search_channels /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html - #[cfg(feature = "methods")] + #[cfg(feature="methods")] pub fn search<F>(&self, f: F) -> Result<SearchResult> where F: FnOnce(Search) -> Search { #[cfg(feature="cache")] diff --git a/src/model/misc.rs b/src/model/misc.rs index 5d9017d..f3632a5 100644 --- a/src/model/misc.rs +++ b/src/model/misc.rs @@ -81,6 +81,7 @@ impl Mentionable for User { #[cfg(all(feature="cache", feature="methods"))] impl FromStr for User { type Err = (); + fn from_str(s: &str) -> StdResult<Self, ()> { match utils::parse_username(s) { Some(x) => { @@ -96,6 +97,7 @@ impl FromStr for User { impl FromStr for UserId { type Err = (); + fn from_str(s: &str) -> StdResult<Self, ()> { utils::parse_username(s).ok_or_else(|| ()).map(UserId) } @@ -104,6 +106,7 @@ impl FromStr for UserId { #[cfg(all(feature="cache", feature="methods"))] impl FromStr for Role { type Err = (); + fn from_str(s: &str) -> StdResult<Self, ()> { match utils::parse_role(s) { Some(x) => { @@ -119,6 +122,7 @@ impl FromStr for Role { impl FromStr for RoleId { type Err = (); + fn from_str(s: &str) -> StdResult<Self, ()> { utils::parse_role(s).ok_or_else(|| ()).map(RoleId) } @@ -135,6 +139,7 @@ impl EmojiIdentifier { impl FromStr for EmojiIdentifier { type Err = (); + fn from_str(s: &str) -> StdResult<Self, ()> { utils::parse_emoji(s).ok_or_else(|| ()) } @@ -142,6 +147,7 @@ impl FromStr for EmojiIdentifier { impl FromStr for ChannelId { type Err = (); + fn from_str(s: &str) -> StdResult<Self, ()> { utils::parse_channel(s).ok_or_else(|| ()).map(ChannelId) } @@ -150,6 +156,7 @@ impl FromStr for ChannelId { #[cfg(all(feature="cache", feature="methods"))] impl FromStr for Channel { type Err = (); + fn from_str(s: &str) -> StdResult<Self, ()> { match utils::parse_channel(s) { Some(x) => { diff --git a/src/model/user.rs b/src/model/user.rs index 4875e6f..d5d7027 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -222,7 +222,6 @@ impl User { /// [`GuildId`]: struct.GuildId.html /// [`Role`]: struct.Role.html /// [`Cache`]: ../ext/cache/struct.Cache.html - #[allow(unused_variables)] // no-cache would warn on guild_id. pub fn has_role<G, R>(&self, guild: G, role: R) -> bool where G: Into<GuildContainer>, R: Into<RoleId> { diff --git a/src/model/utils.rs b/src/model/utils.rs index e499fd2..71b4a52 100644 --- a/src/model/utils.rs +++ b/src/model/utils.rs @@ -29,9 +29,9 @@ use ::ext::cache::ChannelRef; macro_rules! req { ($opt:expr) => { $opt.ok_or(Error::Decode(concat!("Type mismatch in model:", - line!(), - ": ", - stringify!($opt)), + line!(), + ": ", + stringify!($opt)), Value::Null))? } } @@ -100,6 +100,9 @@ pub fn decode_members(value: Value) -> Result<HashMap<UserId, Member>> { } // Clippy's lint is incorrect here and will result in invalid code. +// +// Bit more detaul: `result_unwrap_or_default` is not yet stable as of rustc +// 1.14. #[allow(or_fun_call)] pub fn decode_notes(value: Value) -> Result<HashMap<UserId, String>> { let mut notes = HashMap::new(); @@ -263,7 +266,8 @@ pub fn into_u64(value: Value) -> Result<u64> { } } -pub fn opt<T, F: FnOnce(Value) -> Result<T>>(map: &mut BTreeMap<String, Value>, key: &str, f: F) -> Result<Option<T>> { +pub fn opt<F, T>(map: &mut BTreeMap<String, Value>, key: &str, f: F) + -> Result<Option<T>> where F: FnOnce(Value) -> Result<T> { match map.remove(key) { None | Some(Value::Null) => Ok(None), Some(val) => f(val).map(Some), @@ -289,7 +293,6 @@ pub fn remove(map: &mut BTreeMap<String, Value>, key: &str) -> Result<Value> { }) } -#[doc(hidden)] #[cfg(all(feature="cache", feature="methods"))] pub fn user_has_perms(channel_id: ChannelId, mut permissions: Permissions) |