Skip to content

Commit

Permalink
Remove impl Into<Option> (serenity-rs#2701)
Browse files Browse the repository at this point in the history
This signature is hard to use as `None` cannot infer the type of the
generic. I also replaced `Option<u8>` with `Option<NonMaxU8>` as it's
more efficient and will make the user think of the maximum value.
  • Loading branch information
GnomedDev authored and arqunis committed Jan 16, 2024
1 parent 2717cfa commit 8ddd656
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/builder/edit_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ impl<'a> EditChannel<'a> {
/// [text]: ChannelType::Text
/// [voice]: ChannelType::Voice
#[inline]
pub fn category<C: Into<Option<ChannelId>>>(mut self, category: C) -> Self {
self.parent_id = Some(category.into());
pub fn category(mut self, category: Option<ChannelId>) -> Self {
self.parent_id = Some(category);
self
}

Expand Down
2 changes: 1 addition & 1 deletion src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4014,7 +4014,7 @@ impl Http {
message_id: MessageId,
reaction_type: &ReactionType,
limit: u8,
after: Option<u64>,
after: Option<UserId>,
) -> Result<Vec<User>> {
let mut params = ArrayVec::<_, 2>::new();
params.push(("limit", limit.to_string()));
Expand Down
10 changes: 2 additions & 8 deletions src/model/channel/channel_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,18 +619,12 @@ impl ChannelId {
message_id: impl Into<MessageId>,
reaction_type: impl Into<ReactionType>,
limit: Option<u8>,
after: impl Into<Option<UserId>>,
after: Option<UserId>,
) -> Result<Vec<User>> {
let limit = limit.map_or(50, |x| if x > 100 { 100 } else { x });

http.as_ref()
.get_reaction_users(
self,
message_id.into(),
&reaction_type.into(),
limit,
after.into().map(UserId::get),
)
.get_reaction_users(self, message_id.into(), &reaction_type.into(), limit, after)
.await
}

Expand Down
2 changes: 1 addition & 1 deletion src/model/channel/guild_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ impl GuildChannel {
message_id: impl Into<MessageId>,
reaction_type: impl Into<ReactionType>,
limit: Option<u8>,
after: impl Into<Option<UserId>>,
after: Option<UserId>,
) -> Result<Vec<User>> {
self.id.reaction_users(http, message_id, reaction_type, limit, after).await
}
Expand Down
2 changes: 1 addition & 1 deletion src/model/channel/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ impl Message {
http: impl AsRef<Http>,
reaction_type: impl Into<ReactionType>,
limit: Option<u8>,
after: impl Into<Option<UserId>>,
after: Option<UserId>,
) -> Result<Vec<User>> {
self.channel_id.reaction_users(http, self.id, reaction_type, limit, after).await
}
Expand Down
2 changes: 1 addition & 1 deletion src/model/channel/private_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ impl PrivateChannel {
message_id: impl Into<MessageId>,
reaction_type: impl Into<ReactionType>,
limit: Option<u8>,
after: impl Into<Option<UserId>>,
after: Option<UserId>,
) -> Result<Vec<User>> {
self.id.reaction_users(http, message_id, reaction_type, limit, after).await
}
Expand Down
15 changes: 5 additions & 10 deletions src/model/channel/reaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::fmt::Display as _;
use std::fmt::{self, Write as _};
use std::str::FromStr;

use nonmax::NonMaxU8;
#[cfg(feature = "http")]
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
use serde::de::{Deserialize, Error as DeError};
Expand Down Expand Up @@ -216,7 +217,7 @@ impl Reaction {
&self,
http: impl AsRef<Http>,
reaction_type: R,
limit: Option<u8>,
limit: Option<NonMaxU8>,
after: Option<U>,
) -> Result<Vec<User>>
where
Expand All @@ -230,24 +231,18 @@ impl Reaction {
&self,
http: impl AsRef<Http>,
reaction_type: &ReactionType,
limit: Option<u8>,
limit: Option<NonMaxU8>,
after: Option<UserId>,
) -> Result<Vec<User>> {
let mut limit = limit.unwrap_or(50);
let mut limit = limit.map_or(50, |limit| limit.get());

if limit > 100 {
limit = 100;
warn!("Reaction users limit clamped to 100! (API Restriction)");
}

http.as_ref()
.get_reaction_users(
self.channel_id,
self.message_id,
reaction_type,
limit,
after.map(UserId::get),
)
.get_reaction_users(self.channel_id, self.message_id, reaction_type, limit, after)
.await
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/model/guild/guild_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1102,9 +1102,9 @@ impl GuildId {
self,
http: impl AsRef<Http>,
limit: Option<u64>,
after: impl Into<Option<UserId>>,
after: Option<UserId>,
) -> Result<Vec<Member>> {
http.as_ref().get_guild_members(self, limit, after.into().map(UserId::get)).await
http.as_ref().get_guild_members(self, limit, after.map(UserId::get)).await
}

/// Streams over all the members in a guild.
Expand Down
2 changes: 1 addition & 1 deletion src/model/guild/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ impl Guild {
&self,
http: impl AsRef<Http>,
limit: Option<u64>,
after: impl Into<Option<UserId>>,
after: Option<UserId>,
) -> Result<Vec<Member>> {
self.id.members(http, limit, after).await
}
Expand Down
2 changes: 1 addition & 1 deletion src/model/guild/partial_guild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ impl PartialGuild {
&self,
http: impl AsRef<Http>,
limit: Option<u64>,
after: impl Into<Option<UserId>>,
after: Option<UserId>,
) -> Result<Vec<Member>> {
self.id.members(http, limit, after).await
}
Expand Down

0 comments on commit 8ddd656

Please sign in to comment.