Skip to content

Commit b45cea9

Browse files
committed
unstable
1 parent 8e05df3 commit b45cea9

File tree

12 files changed

+235
-64
lines changed

12 files changed

+235
-64
lines changed

src/builder/create_components.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ use serde::Serialize;
55
use crate::model::prelude::*;
66

77
#[derive(Clone, Debug)]
8+
#[cfg(feature = "unstable")]
89
struct StaticU8<const VAL: u8>;
910

11+
#[cfg(feature = "unstable")]
1012
impl<const VAL: u8> Serialize for StaticU8<VAL> {
1113
fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
1214
ser.serialize_u8(VAL)
@@ -75,6 +77,7 @@ impl serde::Serialize for CreateActionRow<'_> {
7577
#[derive(Clone, Debug, Serialize)]
7678
#[must_use]
7779
#[serde(untagged)]
80+
#[cfg(feature = "unstable")]
7881
pub enum CreateComponent<'a> {
7982
/// Represents an action row component (V1).
8083
///
@@ -112,6 +115,7 @@ pub enum CreateComponent<'a> {
112115
/// accessory.
113116
#[derive(Clone, Debug, Serialize)]
114117
#[must_use]
118+
#[cfg(feature = "unstable")]
115119
pub struct CreateSection<'a> {
116120
#[serde(rename = "type")]
117121
kind: StaticU8<9>,
@@ -120,6 +124,7 @@ pub struct CreateSection<'a> {
120124
accessory: CreateSectionAccessory<'a>,
121125
}
122126

127+
#[cfg(feature = "unstable")]
123128
impl<'a> CreateSection<'a> {
124129
/// Creates a new builder with the specified components and accessory.
125130
///
@@ -166,19 +171,22 @@ impl<'a> CreateSection<'a> {
166171
#[derive(Clone, Debug, Serialize)]
167172
#[must_use]
168173
#[serde(untagged)]
174+
#[cfg(feature = "unstable")]
169175
pub enum CreateSectionComponent<'a> {
170176
TextDisplay(CreateTextDisplay<'a>),
171177
}
172178

173179
/// A builder to create a text display component.
174180
#[derive(Clone, Debug, Serialize)]
175181
#[must_use]
182+
#[cfg(feature = "unstable")]
176183
pub struct CreateTextDisplay<'a> {
177184
#[serde(rename = "type")]
178185
kind: StaticU8<10>,
179186
content: Cow<'a, str>,
180187
}
181188

189+
#[cfg(feature = "unstable")]
182190
impl<'a> CreateTextDisplay<'a> {
183191
/// Creates a new text display component.
184192
///
@@ -204,6 +212,7 @@ impl<'a> CreateTextDisplay<'a> {
204212
#[derive(Clone, Debug, Serialize)]
205213
#[must_use]
206214
#[serde(untagged)]
215+
#[cfg(feature = "unstable")]
207216
pub enum CreateSectionAccessory<'a> {
208217
Thumbnail(CreateThumbnail<'a>),
209218
Button(CreateButton<'a>),
@@ -212,6 +221,7 @@ pub enum CreateSectionAccessory<'a> {
212221
/// A builder to create a thumbnail for a section.
213222
#[derive(Clone, Debug, Serialize)]
214223
#[must_use]
224+
#[cfg(feature = "unstable")]
215225
pub struct CreateThumbnail<'a> {
216226
#[serde(rename = "type")]
217227
kind: StaticU8<11>,
@@ -222,6 +232,7 @@ pub struct CreateThumbnail<'a> {
222232
spoiler: Option<bool>,
223233
}
224234

235+
#[cfg(feature = "unstable")]
225236
impl<'a> CreateThumbnail<'a> {
226237
/// Creates a new thumbnail with a media item.
227238
pub fn new(media: CreateUnfurledMediaItem<'a>) -> Self {
@@ -255,10 +266,12 @@ impl<'a> CreateThumbnail<'a> {
255266
/// A builder to create a media item.
256267
#[derive(Clone, Debug, Serialize, Default)]
257268
#[must_use]
269+
#[cfg(feature = "unstable")]
258270
pub struct CreateUnfurledMediaItem<'a> {
259271
url: Cow<'a, str>,
260272
}
261273

274+
#[cfg(feature = "unstable")]
262275
impl<'a> CreateUnfurledMediaItem<'a> {
263276
/// Creates a new media item.
264277
pub fn new(url: impl Into<Cow<'a, str>>) -> Self {
@@ -279,12 +292,14 @@ impl<'a> CreateUnfurledMediaItem<'a> {
279292
/// Note: May contain up to **10** items.
280293
#[derive(Clone, Debug, Serialize)]
281294
#[must_use]
295+
#[cfg(feature = "unstable")]
282296
pub struct CreateMediaGallery<'a> {
283297
#[serde(rename = "type")]
284298
kind: StaticU8<12>,
285299
items: Cow<'a, [CreateMediaGalleryItem<'a>]>,
286300
}
287301

302+
#[cfg(feature = "unstable")]
288303
impl<'a> CreateMediaGallery<'a> {
289304
/// Creates a new media gallery with up to **10** items.
290305
pub fn new(items: impl Into<Cow<'a, [CreateMediaGalleryItem<'a>]>>) -> Self {
@@ -315,6 +330,7 @@ impl<'a> CreateMediaGallery<'a> {
315330
/// Builder to create individual media gallery items.
316331
#[derive(Clone, Debug, Serialize, Default)]
317332
#[must_use]
333+
#[cfg(feature = "unstable")]
318334
pub struct CreateMediaGalleryItem<'a> {
319335
media: CreateUnfurledMediaItem<'a>,
320336
#[serde(skip_serializing_if = "Option::is_none")]
@@ -323,6 +339,7 @@ pub struct CreateMediaGalleryItem<'a> {
323339
spoiler: Option<bool>,
324340
}
325341

342+
#[cfg(feature = "unstable")]
326343
impl<'a> CreateMediaGalleryItem<'a> {
327344
/// Create a new media gallery item.
328345
pub fn new(media: CreateUnfurledMediaItem<'a>) -> Self {
@@ -372,6 +389,7 @@ impl<'a> CreateMediaGalleryItem<'a> {
372389
/// refer to the [Discord Documentation](https://discord.com/developers/docs/reference#uploading-files).
373390
#[derive(Clone, Debug, Serialize)]
374391
#[must_use]
392+
#[cfg(feature = "unstable")]
375393
pub struct CreateFile<'a> {
376394
#[serde(rename = "type")]
377395
kind: StaticU8<13>,
@@ -380,6 +398,7 @@ pub struct CreateFile<'a> {
380398
spoiler: Option<bool>,
381399
}
382400

401+
#[cfg(feature = "unstable")]
383402
impl<'a> CreateFile<'a> {
384403
/// Create a new builder for the file component. Refer to this builders documentation for
385404
/// limits.
@@ -408,6 +427,7 @@ impl<'a> CreateFile<'a> {
408427
/// A builder for creating a separator.
409428
#[derive(Clone, Debug, Serialize)]
410429
#[must_use]
430+
#[cfg(feature = "unstable")]
411431
pub struct CreateSeparator {
412432
#[serde(rename = "type")]
413433
kind: StaticU8<14>,
@@ -416,6 +436,7 @@ pub struct CreateSeparator {
416436
spacing: Option<Spacing>,
417437
}
418438

439+
#[cfg(feature = "unstable")]
419440
impl CreateSeparator {
420441
/// Creates a new separator, with or without a divider.
421442
pub fn new(divider: bool) -> Self {
@@ -443,6 +464,7 @@ impl CreateSeparator {
443464
/// A builder to create a container, which acts similarly to embeds.
444465
#[derive(Clone, Debug, Serialize)]
445466
#[must_use]
467+
#[cfg(feature = "unstable")]
446468
pub struct CreateContainer<'a> {
447469
#[serde(rename = "type")]
448470
kind: StaticU8<17>,
@@ -453,6 +475,7 @@ pub struct CreateContainer<'a> {
453475
components: Cow<'a, [CreateComponent<'a>]>,
454476
}
455477

478+
#[cfg(feature = "unstable")]
456479
impl<'a> CreateContainer<'a> {
457480
/// Create a new container, with an array of components inside. This component may contain any
458481
/// other component except another container!

src/builder/create_interaction_response.rs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
use std::borrow::Cow;
22
use std::collections::HashMap;
33

4+
#[cfg(not(feature = "unstable"))]
5+
use super::CreateActionRow;
6+
#[cfg(feature = "unstable")]
7+
use super::CreateComponent;
48
use super::create_poll::Ready;
5-
use super::{
6-
CreateAllowedMentions,
7-
CreateAttachment,
8-
CreateComponent,
9-
CreateEmbed,
10-
CreatePoll,
11-
EditAttachments,
12-
};
9+
use super::{CreateAllowedMentions, CreateAttachment, CreateEmbed, CreatePoll, EditAttachments};
1310
#[cfg(feature = "http")]
1411
use crate::http::Http;
1512
use crate::internal::prelude::*;
@@ -160,8 +157,12 @@ pub struct CreateInteractionResponseMessage<'a> {
160157
#[serde(skip_serializing_if = "Option::is_none")]
161158
flags: Option<InteractionResponseFlags>,
162159
#[serde(skip_serializing_if = "Option::is_none")]
160+
#[cfg(feature = "unstable")]
163161
components: Option<Cow<'a, [CreateComponent<'a>]>>,
164162
#[serde(skip_serializing_if = "Option::is_none")]
163+
#[cfg(not(feature = "unstable"))]
164+
components: Option<Cow<'a, [CreateActionRow<'a>]>>,
165+
#[serde(skip_serializing_if = "Option::is_none")]
165166
poll: Option<CreatePoll<'a, Ready>>,
166167
attachments: EditAttachments<'a>,
167168
}
@@ -273,11 +274,19 @@ impl<'a> CreateInteractionResponseMessage<'a> {
273274
}
274275

275276
/// Sets the components of this message.
277+
#[cfg(feature = "unstable")]
276278
pub fn components(mut self, components: impl Into<Cow<'a, [CreateComponent<'a>]>>) -> Self {
277279
self.components = Some(components.into());
278280
self
279281
}
280282

283+
/// Sets the components of this message.
284+
#[cfg(not(feature = "unstable"))]
285+
pub fn components(mut self, components: impl Into<Cow<'a, [CreateActionRow<'a>]>>) -> Self {
286+
self.components = Some(components.into());
287+
self
288+
}
289+
281290
/// Adds a poll to the message. Only one poll can be added per message.
282291
///
283292
/// See [`CreatePoll`] for more information on creating and configuring a poll.
@@ -423,6 +432,9 @@ impl<'a> CreateAutocompleteResponse<'a> {
423432
#[derive(Clone, Debug, Default, Serialize)]
424433
#[must_use]
425434
pub struct CreateModal<'a> {
435+
#[cfg(not(feature = "unstable"))]
436+
components: Cow<'a, [CreateActionRow<'a>]>,
437+
#[cfg(feature = "unstable")]
426438
components: Cow<'a, [CreateComponent<'a>]>,
427439
custom_id: Cow<'a, str>,
428440
title: Cow<'a, str>,
@@ -441,8 +453,18 @@ impl<'a> CreateModal<'a> {
441453
/// Sets the components of this message.
442454
///
443455
/// Overwrites existing components.
456+
#[cfg(feature = "unstable")]
444457
pub fn components(mut self, components: impl Into<Cow<'a, [CreateComponent<'a>]>>) -> Self {
445458
self.components = components.into();
446459
self
447460
}
461+
462+
/// Sets the components of this message.
463+
///
464+
/// Overwrites existing components.
465+
#[cfg(not(feature = "unstable"))]
466+
pub fn components(mut self, components: impl Into<Cow<'a, [CreateActionRow<'a>]>>) -> Self {
467+
self.components = components.into();
468+
self
469+
}
448470
}

src/builder/create_interaction_response_followup.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
use std::borrow::Cow;
22

3+
#[cfg(not(feature = "unstable"))]
4+
use super::CreateActionRow;
5+
#[cfg(feature = "unstable")]
6+
use super::CreateComponent;
37
use super::create_poll::Ready;
4-
use super::{
5-
CreateAllowedMentions,
6-
CreateAttachment,
7-
CreateComponent,
8-
CreateEmbed,
9-
CreatePoll,
10-
EditAttachments,
11-
};
8+
use super::{CreateAllowedMentions, CreateAttachment, CreateEmbed, CreatePoll, EditAttachments};
129
#[cfg(feature = "http")]
1310
use crate::http::Http;
1411
#[cfg(feature = "http")]
@@ -29,8 +26,12 @@ pub struct CreateInteractionResponseFollowup<'a> {
2926
#[serde(skip_serializing_if = "Option::is_none")]
3027
allowed_mentions: Option<CreateAllowedMentions<'a>>,
3128
#[serde(skip_serializing_if = "Option::is_none")]
29+
#[cfg(feature = "unstable")]
3230
components: Option<Cow<'a, [CreateComponent<'a>]>>,
3331
#[serde(skip_serializing_if = "Option::is_none")]
32+
#[cfg(not(feature = "unstable"))]
33+
components: Option<Cow<'a, [CreateActionRow<'a>]>>,
34+
#[serde(skip_serializing_if = "Option::is_none")]
3435
flags: Option<MessageFlags>,
3536
#[serde(skip_serializing_if = "Option::is_none")]
3637
poll: Option<CreatePoll<'a, Ready>>,
@@ -153,10 +154,18 @@ impl<'a> CreateInteractionResponseFollowup<'a> {
153154
}
154155

155156
/// Sets the components of this message.
157+
#[cfg(not(feature = "unstable"))]
158+
pub fn components(mut self, components: impl Into<Cow<'a, [CreateActionRow<'a>]>>) -> Self {
159+
self.components = Some(components.into());
160+
self
161+
}
162+
163+
#[cfg(feature = "unstable")]
156164
pub fn components(mut self, components: impl Into<Cow<'a, [CreateComponent<'a>]>>) -> Self {
157165
self.components = Some(components.into());
158166
self
159167
}
168+
160169
super::button_and_select_menu_convenience_methods!(self.components);
161170

162171
/// Creates or edits a followup response to the response sent. If a [`MessageId`] is provided,

src/builder/create_message.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
use std::borrow::Cow;
22

3+
#[cfg(not(feature = "unstable"))]
4+
use super::CreateActionRow;
5+
#[cfg(feature = "unstable")]
6+
use super::CreateComponent;
37
use super::create_poll::Ready;
4-
use super::{
5-
CreateAllowedMentions,
6-
CreateAttachment,
7-
CreateComponent,
8-
CreateEmbed,
9-
CreatePoll,
10-
EditAttachments,
11-
};
8+
use super::{CreateAllowedMentions, CreateAttachment, CreateEmbed, CreatePoll, EditAttachments};
129
#[cfg(feature = "http")]
1310
use crate::http::Http;
1411
#[cfg(feature = "http")]
@@ -63,7 +60,11 @@ pub struct CreateMessage<'a> {
6360
#[serde(skip_serializing_if = "Option::is_none")]
6461
message_reference: Option<MessageReference>,
6562
#[serde(skip_serializing_if = "Option::is_none")]
63+
#[cfg(feature = "unstable")]
6664
components: Option<Cow<'a, [CreateComponent<'a>]>>,
65+
#[serde(skip_serializing_if = "Option::is_none")]
66+
#[cfg(not(feature = "unstable"))]
67+
components: Option<Cow<'a, [CreateActionRow<'a>]>>,
6768
sticker_ids: Cow<'a, [StickerId]>,
6869
#[serde(skip_serializing_if = "Option::is_none")]
6970
flags: Option<MessageFlags>,
@@ -194,10 +195,19 @@ impl<'a> CreateMessage<'a> {
194195
}
195196

196197
/// Sets the components of this message.
198+
#[cfg(feature = "unstable")]
197199
pub fn components(mut self, components: impl Into<Cow<'a, [CreateComponent<'a>]>>) -> Self {
198200
self.components = Some(components.into());
199201
self
200202
}
203+
204+
/// Sets the components of this message.
205+
#[cfg(not(feature = "unstable"))]
206+
pub fn components(mut self, components: impl Into<Cow<'a, [CreateActionRow<'a>]>>) -> Self {
207+
self.components = Some(components.into());
208+
self
209+
}
210+
201211
super::button_and_select_menu_convenience_methods!(self.components);
202212

203213
/// Sets the flags for the message.

src/builder/edit_interaction_response.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
use std::borrow::Cow;
22

3+
#[cfg(not(feature = "unstable"))]
4+
use super::CreateActionRow;
5+
#[cfg(feature = "unstable")]
6+
use super::CreateComponent;
37
use super::{
48
CreateAllowedMentions,
59
CreateAttachment,
6-
CreateComponent,
710
CreateEmbed,
811
EditAttachments,
912
EditWebhookMessage,
@@ -70,9 +73,17 @@ impl<'a> EditInteractionResponse<'a> {
7073
}
7174

7275
/// Sets the components of this message.
76+
#[cfg(feature = "unstable")]
7377
pub fn components(self, components: impl Into<Cow<'a, [CreateComponent<'a>]>>) -> Self {
7478
Self(self.0.components(components))
7579
}
80+
81+
/// Sets the components of this message.
82+
#[cfg(not(feature = "unstable"))]
83+
pub fn components(self, components: impl Into<Cow<'a, [CreateActionRow<'a>]>>) -> Self {
84+
Self(self.0.components(components))
85+
}
86+
7687
super::button_and_select_menu_convenience_methods!(self.0.components);
7788

7889
/// Sets attachments, see [`EditAttachments`] for more details.

0 commit comments

Comments
 (0)