Skip to content

Commit 7813f16

Browse files
GnomedDevmkrasnitski
authored andcommitted
More followups to Thread Split PR (serenity-rs#3352)
1 parent 8237a5f commit 7813f16

File tree

9 files changed

+32
-12
lines changed

9 files changed

+32
-12
lines changed

src/builder/create_forum_post.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<'a> CreateForumPost<'a> {
9898
///
9999
/// Returns [`Error::Http`] if the current user lacks permission, or if invalid data is given.
100100
#[cfg(feature = "http")]
101-
pub async fn execute(self, http: &Http, channel_id: ChannelId) -> Result<GuildChannel> {
101+
pub async fn execute(self, http: &Http, channel_id: ChannelId) -> Result<GuildThread> {
102102
let files = self.message.attachments.new_attachments();
103103
http.create_forum_post(channel_id, &self, files, self.audit_log_reason).await
104104
}

src/builder/create_thread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<'a> CreateThread<'a> {
107107
http: &Http,
108108
channel_id: ChannelId,
109109
message_id: Option<MessageId>,
110-
) -> Result<GuildChannel> {
110+
) -> Result<GuildThread> {
111111
match message_id {
112112
Some(id) => {
113113
http.create_thread_from_message(channel_id, id, &self, self.audit_log_reason).await

src/http/client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ impl Http {
435435
message_id: MessageId,
436436
map: &impl serde::Serialize,
437437
audit_log_reason: Option<&str>,
438-
) -> Result<GuildChannel> {
438+
) -> Result<GuildThread> {
439439
let body = to_vec(map)?;
440440

441441
self.fire(Request {
@@ -458,7 +458,7 @@ impl Http {
458458
channel_id: ChannelId,
459459
map: &impl serde::Serialize,
460460
audit_log_reason: Option<&str>,
461-
) -> Result<GuildChannel> {
461+
) -> Result<GuildThread> {
462462
let body = to_vec(map)?;
463463

464464
self.fire(Request {
@@ -481,7 +481,7 @@ impl Http {
481481
map: &impl serde::Serialize,
482482
files: Vec<CreateAttachment<'_>>,
483483
audit_log_reason: Option<&str>,
484-
) -> Result<GuildChannel> {
484+
) -> Result<GuildThread> {
485485
self.fire(Request {
486486
body: None,
487487
multipart: Some(Multipart {

src/model/channel/channel_id.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ impl ChannelId {
319319
http: &Http,
320320
message_id: MessageId,
321321
builder: CreateThread<'_>,
322-
) -> Result<GuildChannel> {
322+
) -> Result<GuildThread> {
323323
builder.execute(http, self, Some(message_id)).await
324324
}
325325

@@ -333,7 +333,7 @@ impl ChannelId {
333333
self,
334334
http: &Http,
335335
builder: CreateThread<'_>,
336-
) -> Result<GuildChannel> {
336+
) -> Result<GuildThread> {
337337
builder.execute(http, self, None).await
338338
}
339339

@@ -346,7 +346,7 @@ impl ChannelId {
346346
self,
347347
http: &Http,
348348
builder: CreateForumPost<'_>,
349-
) -> Result<GuildChannel> {
349+
) -> Result<GuildThread> {
350350
builder.execute(http, self).await
351351
}
352352

src/model/channel/message.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub struct Message {
107107
/// [`Interaction`]: crate::model::application::Interaction
108108
pub interaction_metadata: Option<Box<MessageInteractionMetadata>>,
109109
/// The thread that was started from this message, includes thread member object.
110-
pub thread: Option<Box<GuildChannel>>,
110+
pub thread: Option<Box<GuildThread>>,
111111
/// The components of this message
112112
#[serde(default, deserialize_with = "deserialize_components")]
113113
pub components: FixedArray<ActionRow>,

src/model/channel/mod.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,32 @@ impl From<ChannelId> for GenericChannelId {
4545
}
4646

4747
impl GenericChannelId {
48+
/// Copies this ID into a [`ChannelId`] and a [`ThreadId`].
49+
///
50+
/// It is only correct to use this when you use both returned values,
51+
/// otherwise use [`Self::expect_channel`] or [`Self::expect_thread`].
4852
#[must_use]
4953
pub fn split(self) -> (ChannelId, ThreadId) {
5054
(self.expect_channel(), self.expect_thread())
5155
}
5256

57+
/// Converts the type of this Id to [`ChannelId`].
58+
///
59+
/// This converts the type without changing the inner value, therefore,
60+
/// is only correct when you have knowledge which is not in the type system.
61+
///
62+
/// This should be used as rarely as [`Option::expect`].
5363
#[must_use]
5464
pub fn expect_channel(self) -> ChannelId {
5565
ChannelId::new(self.get())
5666
}
5767

68+
/// Converts the type of this Id to [`ThreadId`].
69+
///
70+
/// This converts the type without changing the inner value, therefore,
71+
/// is only correct when you have knowledge which is not in the type system.
72+
///
73+
/// This should be used as rarely as [`Option::expect`].
5874
#[must_use]
5975
pub fn expect_thread(self) -> ThreadId {
6076
ThreadId::new(self.get())
@@ -449,7 +465,7 @@ pub struct StageInstance {
449465
#[non_exhaustive]
450466
pub struct ThreadsData {
451467
/// The threads channels.
452-
pub threads: FixedArray<GuildChannel>,
468+
pub threads: FixedArray<GuildThread>,
453469
/// A thread member for each returned thread the current user has joined.
454470
pub members: FixedArray<ThreadMember>,
455471
/// Whether there are potentially more threads that could be returned on a subsequent call.

src/model/channel/thread.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ use crate::internal::prelude::*;
77
use crate::model::utils::is_false;
88

99
impl ThreadId {
10+
/// Converts the type of this Id to [`GenericChannelId`].
11+
///
12+
/// This allows you to call methods which are shared between channels and threads, and does not
13+
/// change the inner value at all.
1014
#[must_use]
1115
pub fn widen(self) -> GenericChannelId {
1216
self.into()

src/model/event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ pub struct GuildCreateEvent {
162162
pub guild: Guild,
163163
}
164164

165-
// Manual impl needed to insert guild_id fields in GuildChannel, Member, Role
165+
// Manual impl needed to insert guild_id fields in GuildChannel, GuildThread, Member, Role
166166
impl<'de> Deserialize<'de> for GuildCreateEvent {
167167
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> StdResult<Self, D::Error> {
168168
let mut guild: Guild = Guild::deserialize(deserializer)?;

src/model/guild/audit_log/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ pub struct AuditLogs {
332332
///
333333
/// Threads referenced in THREAD_CREATE and THREAD_UPDATE events are included in the threads
334334
/// map since archived threads might not be kept in memory by clients.
335-
pub threads: FixedArray<GuildChannel>,
335+
pub threads: FixedArray<GuildThread>,
336336
/// List of users referenced in the audit log.
337337
pub users: ExtractMap<UserId, User>,
338338
/// List of webhooks referenced in the audit log.

0 commit comments

Comments
 (0)