Skip to content

Commit

Permalink
Signify code that needs the collector feature (#1274)
Browse files Browse the repository at this point in the history
This adds `#[doc(cfg(feature = "collector"))]` for all structures and functions that need the `collector` feature to be enabled in order to be used. This is done similarly like the `unstable_discord_api` feature, as just like the `collector` feature, it's disabled by default and it's not apparent to the user in the documentation that certain code requires a feature.
  • Loading branch information
arqunis authored Mar 30, 2021
1 parent cc184a4 commit a04291f
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/client/bridge/gateway/shard_messenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,15 @@ impl ShardMessenger {
/// Sets a new filter for a message collector.
#[inline]
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn set_message_filter(&self, collector: MessageFilter) {
#[allow(clippy::let_underscore_must_use)]
let _ = self.send_to_shard(ShardRunnerMessage::SetMessageFilter(collector));
}

/// Sets a new filter for a message collector.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn set_reaction_filter(&self, collector: ReactionFilter) {
#[allow(clippy::let_underscore_must_use)]
let _ = self.send_to_shard(ShardRunnerMessage::SetReactionFilter(collector));
Expand Down
2 changes: 2 additions & 0 deletions src/client/bridge/gateway/shard_runner_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ pub enum ShardRunnerMessage {
SetStatus(OnlineStatus),
/// Sends a new filter for messages to the shard.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
SetMessageFilter(MessageFilter),
/// Sends a new filter for reactions to the shard.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
SetReactionFilter(ReactionFilter),
}
2 changes: 2 additions & 0 deletions src/client/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ impl Context {
/// sent back to `filter`'s paired receiver.
#[inline]
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub async fn set_message_filter(&self, filter: MessageFilter) {
self.shard.set_message_filter(filter);
}
Expand All @@ -397,6 +398,7 @@ impl Context {
/// sent back to `filter`'s paired receiver.
#[inline]
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub async fn set_reaction_filter(&self, filter: ReactionFilter) {
self.shard.set_reaction_filter(filter);
}
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub mod cache;
#[cfg(feature = "client")]
pub mod client;
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub mod collector;
#[cfg(feature = "framework")]
pub mod framework;
Expand Down
4 changes: 4 additions & 0 deletions src/model/channel/channel_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,7 @@ impl ChannelId {

/// Returns a future that will await one message sent in this channel.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn await_reply<'a>(
&self,
shard_messenger: &'a impl AsRef<ShardMessenger>,
Expand All @@ -849,6 +850,7 @@ impl ChannelId {

/// Returns a stream builder which can be awaited to obtain a stream of messages in this channel.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn await_replies<'a>(
&self,
shard_messenger: &'a impl AsRef<ShardMessenger>,
Expand All @@ -858,6 +860,7 @@ impl ChannelId {

/// Await a single reaction in this guild.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn await_reaction<'a>(
&self,
shard_messenger: &'a impl AsRef<ShardMessenger>,
Expand All @@ -867,6 +870,7 @@ impl ChannelId {

/// Returns a stream builder which can be awaited to obtain a stream of reactions sent in this channel.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn await_reactions<'a>(
&self,
shard_messenger: &'a impl AsRef<ShardMessenger>,
Expand Down
4 changes: 4 additions & 0 deletions src/model/channel/guild_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,7 @@ impl GuildChannel {

/// Returns a future that will await one message by this guild.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn await_reply<'a>(
&self,
shard_messenger: &'a impl AsRef<ShardMessenger>,
Expand All @@ -950,6 +951,7 @@ impl GuildChannel {

/// Returns a stream builder which can be awaited to obtain a stream of messages sent by this guild.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn await_replies<'a>(
&self,
shard_messenger: &'a impl AsRef<ShardMessenger>,
Expand All @@ -959,6 +961,7 @@ impl GuildChannel {

/// Await a single reaction by this guild.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn await_reaction<'a>(
&self,
shard_messenger: &'a impl AsRef<ShardMessenger>,
Expand All @@ -968,6 +971,7 @@ impl GuildChannel {

/// Returns a stream builder which can be awaited to obtain a stream of reactions sent by this guild.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn await_reactions<'a>(
&self,
shard_messenger: &'a impl AsRef<ShardMessenger>,
Expand Down
2 changes: 2 additions & 0 deletions src/model/channel/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ impl Message {

/// Await a single reaction on this message.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn await_reaction<'a>(
&self,
shard_messenger: &'a impl AsRef<ShardMessenger>,
Expand All @@ -821,6 +822,7 @@ impl Message {

/// Returns a stream builder which can be awaited to obtain a stream of reactions on this message.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn await_reactions<'a>(
&self,
shard_messenger: &'a impl AsRef<ShardMessenger>,
Expand Down
4 changes: 4 additions & 0 deletions src/model/guild/guild_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,7 @@ impl GuildId {

/// Returns a future that will await one message sent in this guild.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn await_reply<'a>(
&self,
shard_messenger: &'a impl AsRef<ShardMessenger>,
Expand All @@ -1041,6 +1042,7 @@ impl GuildId {

/// Returns a stream builder which can be awaited to obtain a stream of messages in this guild.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn await_replies<'a>(
&self,
shard_messenger: &'a impl AsRef<ShardMessenger>,
Expand All @@ -1050,6 +1052,7 @@ impl GuildId {

/// Await a single reaction in this guild.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn await_reaction<'a>(
&self,
shard_messenger: &'a impl AsRef<ShardMessenger>,
Expand All @@ -1059,6 +1062,7 @@ impl GuildId {

/// Returns a stream builder which can be awaited to obtain a stream of reactions sent in this guild.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn await_reactions<'a>(
&self,
shard_messenger: &'a impl AsRef<ShardMessenger>,
Expand Down
4 changes: 4 additions & 0 deletions src/model/guild/partial_guild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,7 @@ impl PartialGuild {

/// Returns a future that will await one message sent in this guild.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn await_reply<'a>(
&self,
shard_messenger: &'a impl AsRef<ShardMessenger>,
Expand All @@ -824,6 +825,7 @@ impl PartialGuild {

/// Returns a stream builder which can be awaited to obtain a stream of messages in this guild.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn await_replies<'a>(
&self,
shard_messenger: &'a impl AsRef<ShardMessenger>,
Expand All @@ -833,6 +835,7 @@ impl PartialGuild {

/// Await a single reaction in this guild.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn await_reaction<'a>(
&self,
shard_messenger: &'a impl AsRef<ShardMessenger>,
Expand All @@ -842,6 +845,7 @@ impl PartialGuild {

/// Returns a stream builder which can be awaited to obtain a stream of reactions sent in this guild.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn await_reactions<'a>(
&self,
shard_messenger: &'a impl AsRef<ShardMessenger>,
Expand Down
4 changes: 4 additions & 0 deletions src/model/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ impl User {

/// Returns a future that will await one message by this user.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn await_reply<'a>(
&self,
shard_messenger: &'a impl AsRef<ShardMessenger>,
Expand All @@ -878,6 +879,7 @@ impl User {

/// Returns a stream builder which can be awaited to obtain a stream of messages sent by this user.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn await_replies<'a>(
&self,
shard_messenger: &'a impl AsRef<ShardMessenger>,
Expand All @@ -887,6 +889,7 @@ impl User {

/// Await a single reaction by this user.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn await_reaction<'a>(
&self,
shard_messenger: &'a impl AsRef<ShardMessenger>,
Expand All @@ -896,6 +899,7 @@ impl User {

/// Returns a stream builder which can be awaited to obtain a stream of reactions sent by this user.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn await_reactions<'a>(
&self,
shard_messenger: &'a impl AsRef<ShardMessenger>,
Expand Down

0 comments on commit a04291f

Please sign in to comment.