Skip to content

Commit a4b21db

Browse files
authored
Delete passthrough methods (#3023)
This deletes methods which simply pass through to their `id` fields, as they are: - Misleading, as a user may do an HTTP call or cache lookup to get a model just to use it's ID - Lead to a bunch of maintenance issues when having 2..=4 copies of every method. - Hurt compile times, as rustc is having to check signatures, calls, construct async state machines, and maybe even inline to generate code multiple times. For methods which simply only used their `id` field but did not have a version on their respective ID, they were moved to their ID. This doesn't have a corresponding deprecation PR to current, as current still has permission checks and other "helpers" which rely on the model.
1 parent 9cd9c97 commit a4b21db

File tree

23 files changed

+169
-3376
lines changed

23 files changed

+169
-3376
lines changed

examples/e03_struct_utilities/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl EventHandler for Handler {
1919
// In this case, you can direct message a User directly by simply calling a method on
2020
// its instance, with the content of the message.
2121
let builder = CreateMessage::new().content("Hello!");
22-
let dm = msg.author.dm(&context.http, builder).await;
22+
let dm = msg.author.id.dm(&context.http, builder).await;
2323

2424
if let Err(why) = dm {
2525
println!("Error when direct messaging user: {why:?}");

examples/e09_collectors/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ impl EventHandler for Handler {
2727
// There is a method implemented for some models to conveniently collect replies. They
2828
// return a builder that can be turned into a Stream, or here, where we can await a
2929
// single reply
30-
let collector = msg.author.await_reply(ctx.shard.clone()).timeout(Duration::from_secs(10));
30+
let collector =
31+
msg.author.id.await_reply(ctx.shard.clone()).timeout(Duration::from_secs(10));
3132
if let Some(answer) = collector.await {
3233
if answer.content.to_lowercase() == "ferris" {
3334
let _ = answer.reply(&ctx.http, "That's correct!").await;
@@ -46,6 +47,7 @@ impl EventHandler for Handler {
4647

4748
// The message model can also be turned into a Collector to collect reactions on it.
4849
let collector = react_msg
50+
.id
4951
.await_reaction(ctx.shard.clone())
5052
.timeout(Duration::from_secs(10))
5153
.author_id(msg.author.id);

examples/e14_message_components/src/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ impl EventHandler for Handler {
5959
// This uses a collector to wait for an incoming event without needing to listen for it
6060
// manually in the EventHandler.
6161
let interaction = match m
62+
.id
6263
.await_component_interaction(ctx.shard.clone())
6364
.timeout(Duration::from_secs(60 * 3))
6465
.await
@@ -106,10 +107,10 @@ impl EventHandler for Handler {
106107
.unwrap();
107108

108109
// Wait for multiple interactions
109-
let mut interaction_stream = m
110-
.await_component_interaction(ctx.shard.clone())
111-
.timeout(Duration::from_secs(60 * 3))
112-
.stream();
110+
let mut interaction_stream =
111+
m.id.await_component_interaction(ctx.shard.clone())
112+
.timeout(Duration::from_secs(60 * 3))
113+
.stream();
113114

114115
while let Some(interaction) = interaction_stream.next().await {
115116
let sound = &interaction.data.custom_id;

examples/testing/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ async fn message(ctx: &Context, msg: Message) -> Result<(), serenity::Error> {
120120
)
121121
.await?;
122122
let button_press = msg
123+
.id
123124
.await_component_interaction(ctx.shard.clone())
124125
.timeout(std::time::Duration::from_secs(10))
125126
.await;
@@ -193,7 +194,7 @@ async fn message(ctx: &Context, msg: Message) -> Result<(), serenity::Error> {
193194
.flags(MessageFlags::IS_VOICE_MESSAGE)
194195
.add_file(CreateAttachment::url(&ctx.http, audio_url, "testing.ogg").await?);
195196

196-
msg.author.dm(&ctx.http, builder).await?;
197+
msg.author.id.dm(&ctx.http, builder).await?;
197198
} else if let Some(channel) = msg.content.strip_prefix("movetorootandback") {
198199
let mut channel = {
199200
let channel_id = channel.trim().parse::<ChannelId>().unwrap();

src/builder/create_channel.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,12 @@ impl<'a> CreateChannel<'a> {
169169
/// Inheriting permissions from an existing channel:
170170
///
171171
/// ```rust,no_run
172-
/// # use serenity::{http::Http, model::guild::Guild};
172+
/// # use serenity::{http::Http, model::id::GuildId};
173173
/// # use std::sync::Arc;
174174
/// #
175175
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
176176
/// # let http: Http = unimplemented!();
177-
/// # let mut guild: Guild = unimplemented!();
177+
/// # let mut guild_id: GuildId = unimplemented!();
178178
/// use serenity::builder::CreateChannel;
179179
/// use serenity::model::channel::{PermissionOverwrite, PermissionOverwriteType};
180180
/// use serenity::model::id::UserId;
@@ -188,7 +188,7 @@ impl<'a> CreateChannel<'a> {
188188
/// }];
189189
///
190190
/// let builder = CreateChannel::new("my_new_cool_channel").permissions(permissions);
191-
/// guild.create_channel(&http, builder).await?;
191+
/// guild_id.create_channel(&http, builder).await?;
192192
/// # Ok(())
193193
/// # }
194194
/// ```

src/builder/create_invite.rs

Lines changed: 3 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::http::Http;
44
use crate::internal::prelude::*;
55
use crate::model::prelude::*;
66

7-
/// A builder to create a [`RichInvite`] for use via [`GuildChannel::create_invite`].
7+
/// A builder to create a [`RichInvite`] for use via [`ChannelId::create_invite`].
88
///
99
/// This is a structured and cleaner way of creating an invite, as all parameters are optional.
1010
///
@@ -16,9 +16,9 @@ use crate::model::prelude::*;
1616
/// # use serenity::{prelude::*, model::prelude::*};
1717
/// use serenity::builder::CreateInvite;
1818
/// use serenity::http::Http;
19-
/// # async fn run(http: &Http, channel: GuildChannel) -> Result<(), Box<dyn std::error::Error>> {
19+
/// # async fn run(http: &Http, channel_id: ChannelId) -> Result<(), Box<dyn std::error::Error>> {
2020
/// let builder = CreateInvite::new().max_age(3600).max_uses(10);
21-
/// let creation = channel.create_invite(http, builder).await?;
21+
/// let creation = channel_id.create_invite(http, builder).await?;
2222
/// # Ok(())
2323
/// # }
2424
/// ```
@@ -57,22 +57,6 @@ impl<'a> CreateInvite<'a> {
5757
/// Set to `0` for an invite which does not expire after an amount of time.
5858
///
5959
/// Defaults to `86400`, or 24 hours.
60-
///
61-
/// # Examples
62-
///
63-
/// Create an invite with a max age of `3600` seconds, or 1 hour:
64-
///
65-
/// ```rust,no_run
66-
/// # use serenity::model::prelude::*;
67-
/// # use serenity::builder::CreateInvite;
68-
/// # use serenity::http::Http;
69-
/// #
70-
/// # async fn example(http: &Http, channel: GuildChannel) -> Result<(), Box<dyn std::error::Error>> {
71-
/// let builder = CreateInvite::new().max_age(3600);
72-
/// let invite = channel.create_invite(http, builder).await?;
73-
/// # Ok(())
74-
/// # }
75-
/// ```
7660
pub fn max_age(mut self, max_age: u32) -> Self {
7761
self.max_age = Some(max_age);
7862
self
@@ -83,24 +67,6 @@ impl<'a> CreateInvite<'a> {
8367
/// Set to `0` for an invite which does not expire after a number of uses.
8468
///
8569
/// Defaults to `0`.
86-
///
87-
/// # Examples
88-
///
89-
/// Create an invite with a max use limit of `5`:
90-
///
91-
/// Create an invite with a max age of `3600` seconds, or 1 hour:
92-
///
93-
/// ```rust,no_run
94-
/// # use serenity::model::prelude::*;
95-
/// # use serenity::builder::CreateInvite;
96-
/// # use serenity::http::Http;
97-
/// #
98-
/// # async fn example(http: &Http, channel: GuildChannel) -> Result<(), Box<dyn std::error::Error>> {
99-
/// let builder = CreateInvite::new().max_uses(5);
100-
/// let invite = channel.create_invite(http, builder).await?;
101-
/// # Ok(())
102-
/// # }
103-
/// ```
10470
pub fn max_uses(mut self, max_uses: u8) -> Self {
10571
self.max_uses = Some(max_uses);
10672
self
@@ -109,22 +75,6 @@ impl<'a> CreateInvite<'a> {
10975
/// Whether an invite grants a temporary membership.
11076
///
11177
/// Defaults to `false`.
112-
///
113-
/// # Examples
114-
///
115-
/// Create an invite which is temporary:
116-
///
117-
/// ```rust,no_run
118-
/// # use serenity::model::prelude::*;
119-
/// # use serenity::builder::CreateInvite;
120-
/// # use serenity::http::Http;
121-
/// #
122-
/// # async fn example(http: &Http, channel: GuildChannel) -> Result<(), Box<dyn std::error::Error>> {
123-
/// let builder = CreateInvite::new().temporary(true);
124-
/// let invite = channel.create_invite(http, builder).await?;
125-
/// # Ok(())
126-
/// # }
127-
/// ```
12878
pub fn temporary(mut self, temporary: bool) -> Self {
12979
self.temporary = Some(temporary);
13080
self
@@ -133,22 +83,6 @@ impl<'a> CreateInvite<'a> {
13383
/// Whether or not to try to reuse a similar invite.
13484
///
13585
/// Defaults to `false`.
136-
///
137-
/// # Examples
138-
///
139-
/// Create an invite which is unique:
140-
///
141-
/// ```rust,no_run
142-
/// # use serenity::model::prelude::*;
143-
/// # use serenity::builder::CreateInvite;
144-
/// # use serenity::http::Http;
145-
/// #
146-
/// # async fn example(http: &Http, channel: GuildChannel) -> Result<(), Box<dyn std::error::Error>> {
147-
/// let builder = CreateInvite::new().unique(true);
148-
/// let invite = channel.create_invite(&http, builder).await?;
149-
/// # Ok(())
150-
/// # }
151-
/// ```
15286
pub fn unique(mut self, unique: bool) -> Self {
15387
self.unique = Some(unique);
15488
self

src/builder/edit_role.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ use crate::model::prelude::*;
99
///
1010
/// These are:
1111
///
12-
/// - [`PartialGuild::create_role`]
13-
/// - [`PartialGuild::edit_role`]
14-
/// - [`Guild::create_role`]
15-
/// - [`Guild::edit_role`]
1612
/// - [`GuildId::create_role`]
1713
/// - [`GuildId::edit_role`]
1814
/// - [`Role::edit`]

src/builder/edit_sticker.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ use crate::model::prelude::*;
1111
///
1212
/// These are:
1313
///
14-
/// - [`Guild::edit_sticker`]
15-
/// - [`PartialGuild::edit_sticker`]
1614
/// - [`GuildId::edit_sticker`]
1715
/// - [`Sticker::edit`]
1816
///

src/builder/get_messages.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::model::prelude::*;
2121
/// The other parameter specifies the number of messages to retrieve. This is _optional_, and
2222
/// defaults to 50 if not specified.
2323
///
24-
/// See [`GuildChannel::messages`] for more examples.
24+
/// See [`ChannelId::messages`] for more examples.
2525
///
2626
/// # Examples
2727
///

src/gateway/client/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ impl Context {
334334
///
335335
/// # Errors
336336
///
337-
/// See [`Guild::create_emoji`] for information about name and filesize requirements. This
337+
/// See [`GuildId::create_emoji`] for information about name and filesize requirements. This
338338
/// method will error if said requirements are not met.
339339
pub async fn create_application_emoji(&self, name: &str, image: &str) -> Result<Emoji> {
340340
#[derive(serde::Serialize)]

0 commit comments

Comments
 (0)