From 3f03f9adc97315bb61a5c71f52365306cb8e2d1a Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Thu, 13 Apr 2017 20:45:56 -0700 Subject: Deprecate methods prefixed with `get_` A lot of structs - such as `Guild` or `ChannelId` - have methods with prefixes of `get_`, which are generally discouraged. To fix this, deprecate them and remove them in v0.3.0. --- src/ext/cache/mod.rs | 84 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 75 insertions(+), 9 deletions(-) (limited to 'src/ext/cache') diff --git a/src/ext/cache/mod.rs b/src/ext/cache/mod.rs index d3479da..59863aa 100644 --- a/src/ext/cache/mod.rs +++ b/src/ext/cache/mod.rs @@ -276,7 +276,7 @@ impl Cache { /// [`get_private_channel`]: #method.get_private_channel /// [`groups`]: #structfield.groups /// [`private_channels`]: #structfield.private_channels - pub fn get_channel>(&self, id: C) -> Option { + pub fn channel>(&self, id: C) -> Option { let id = id.into(); if let Some(channel) = self.channels.get(&id) { @@ -301,7 +301,7 @@ impl Cache { /// /// [`GuildId`]: ../../model/struct.GuildId.html #[inline] - pub fn get_guild>(&self, id: G) -> Option>> { + pub fn guild>(&self, id: G) -> Option>> { self.guilds.get(&id.into()).cloned() } @@ -338,8 +338,7 @@ impl Cache { /// [`Guild`]: ../../model/struct.Guild.html /// [`get_channel`]: #method.get_channel #[inline] - pub fn get_guild_channel>(&self, id: C) - -> Option>> { + pub fn guild_channel>(&self, id: C) -> Option>> { self.channels.get(&id.into()).cloned() } @@ -352,7 +351,7 @@ impl Cache { /// [`ChannelId`]: ../../model/struct.ChannelId.html /// [`Group`]: ../../model/struct.Group.html #[inline] - pub fn get_group>(&self, id: C) -> Option>> { + pub fn group>(&self, id: C) -> Option>> { self.groups.get(&id.into()).cloned() } @@ -401,7 +400,7 @@ impl Cache { /// [`Client::on_message`]: ../../client/struct.Client.html#method.on_message /// [`Guild`]: ../../model/struct.Guild.html /// [`members`]: ../../model/struct.Guild.html#structfield.members - pub fn get_member(&self, guild_id: G, user_id: U) -> Option + pub fn member(&self, guild_id: G, user_id: U) -> Option where G: Into, U: Into { self.guilds .get(&guild_id.into()) @@ -414,7 +413,7 @@ impl Cache { /// The only advantage of this method is that you can pass in anything that /// is indirectly a [`ChannelId`]. #[inline] - pub fn get_private_channel>(&self, channel_id: C) + pub fn private_channel>(&self, channel_id: C) -> Option>> { self.private_channels.get(&channel_id.into()).cloned() } @@ -426,7 +425,7 @@ impl Cache { /// /// [`Guild`]: ../../model/struct.Guild.html /// [`roles`]: ../../model/struct.Guild.html#structfield.roles - pub fn get_role(&self, guild_id: G, role_id: R) -> Option + pub fn role(&self, guild_id: G, role_id: R) -> Option where G: Into, R: Into { self.guilds .get(&guild_id.into()) @@ -441,10 +440,77 @@ impl Cache { /// [`UserId`]: ../../model/struct.UserId.html /// [`users`]: #structfield.users #[inline] - pub fn get_user>(&self, user_id: U) -> Option>> { + pub fn user>(&self, user_id: U) -> Option>> { self.users.get(&user_id.into()).cloned() } + /// Alias of [`channel`]. + /// + /// [`channel`]: #method.channel + #[deprecated(since="0.1.5", note="Use `channel` instead.")] + #[inline] + pub fn get_channel>(&self, id: C) -> Option { + self.channel(id) + } + + /// Alias of [`guild`]. + /// + /// [`guild`]: #method.guild + #[deprecated(since="0.1.5", note="Use `guild` instead.")] + #[inline] + pub fn get_guild>(&self, id: G) -> Option>> { + self.guild(id) + } + + /// Alias of [`guild_channel`]. + /// + /// [`guild_channel`]: #method.guild_channel + #[deprecated(since="0.1.5", note="Use `guild_channel` instead.")] + #[inline] + pub fn get_guild_channel>(&self, id: C) + -> Option>> { + self.guild_channel(id) + } + + /// Alias of [`member`]. + /// + /// [`member`]: #method.member + #[deprecated(since="0.1.5", note="Use `member` instead.")] + #[inline] + pub fn get_member(&self, guild_id: G, user_id: U) -> Option + where G: Into, U: Into { + self.member(guild_id, user_id) + } + + /// Alias of [`private_channel`]. + /// + /// [`private_channel`]: #method.private_channel + #[deprecated(since="0.1.5", note="Use `private_channel` instead.")] + #[inline] + pub fn get_private_channel>(&self, id: C) + -> Option>> { + self.private_channel(id) + } + + /// Alias of [`role`]. + /// + /// [`role`]: #method.role + #[deprecated(since="0.1.5", note="Use `role` instead.")] + #[inline] + pub fn get_role(&self, guild_id: G, role_id: R) -> Option + where G: Into, R: Into { + self.role(guild_id, role_id) + } + + /// Alias of [`user`]. + /// + /// [`user`]: #method.user + #[deprecated(since="0.1.5", note="Use `user` instead.")] + #[inline] + pub fn get_user>(&self, id: U) -> Option>> { + self.user(id) + } + #[doc(hidden)] pub fn update_with_channel_create(&mut self, event: &ChannelCreateEvent) -> Option { match event.channel { -- cgit v1.2.3