@@ -31,8 +31,14 @@ enum_number! {
3131 }
3232}
3333
34- // TODO: doc everything new :sob:
35-
34+ /// Represents Discord components, a part of messages that are usually interactable.
35+ ///
36+ /// # Component Versioning
37+ ///
38+ /// - When `IS_COMPONENTS_V2` is **not** set, the **only** valid top-level component is
39+ /// [`ActionRow`].
40+ /// - When `IS_COMPONENTS_V2` **is** set, other component types may be used at the top level, but
41+ /// other message limitations are applied.
3642#[ cfg_attr( feature = "typesize" , derive( typesize:: derive:: TypeSize ) ) ]
3743#[ derive( Clone , Debug , Serialize ) ]
3844#[ non_exhaustive]
@@ -51,9 +57,6 @@ pub enum Component {
5157 // always update the macro below.
5258}
5359
54- // TODO: add something like this to every variant.
55- // The component type, it will always be [`ComponentType::Thing`].
56-
5760// Define the macro to implement Deserialize
5861macro_rules! impl_deserialize_component {
5962 ( $enum_name: ident, $( $variant: pat => $variant_enum: expr) ,* ) => {
@@ -103,23 +106,38 @@ impl_deserialize_component!(Component,
103106 ComponentType :: Container => Component :: Container
104107) ;
105108
109+ /// A component that is a container for up to 3 text display components and an accessory.
110+ ///
111+ /// [Incomplete Discord docs](https://github.com/Lulalaby/discord-api-docs/pull/30)
106112#[ cfg_attr( feature = "typesize" , derive( typesize:: derive:: TypeSize ) ) ]
107113#[ derive( Clone , Debug , Deserialize , Serialize ) ]
108114#[ non_exhaustive]
109115pub struct Section {
110- components : FixedArray < TextDisplay > ,
116+ /// Always [`ComponentType::Section`]
117+ #[ serde( rename = "type" ) ]
118+ pub kind : ComponentType ,
119+ components : FixedArray < SectionComponent > ,
111120 accessory : SectionAccessory ,
112121}
113122
123+ /// A section component's thumbnail.
124+ ///
125+ /// See [`Section`] for how this fits within a section.
126+ ///
127+ /// [Incomplete Discord docs](https://github.com/Lulalaby/discord-api-docs/pull/30)
114128#[ cfg_attr( feature = "typesize" , derive( typesize:: derive:: TypeSize ) ) ]
115129#[ derive( Clone , Debug , Deserialize , Serialize ) ]
116130#[ non_exhaustive]
117131pub struct Thumbnail {
132+ /// Always [`ComponentType::Thumbnail`]
133+ #[ serde( rename = "type" ) ]
134+ pub kind : ComponentType ,
118135 media : UnfurledMediaItem ,
119136 description : Option < FixedString < u16 > > ,
120137 spoiler : Option < bool > ,
121138}
122139
140+ /// An abstraction over a resolved and unresolved unfurled media item.
123141#[ cfg_attr( feature = "typesize" , derive( typesize:: derive:: TypeSize ) ) ]
124142#[ derive( Clone , Debug , Deserialize , Serialize ) ]
125143#[ non_exhaustive]
@@ -129,13 +147,19 @@ pub enum MediaItem {
129147 Unresolved ( UnfurledMediaItem ) ,
130148}
131149
150+ /// An unfurled media item, stores the url to the item.
151+ ///
152+ /// [Incomplete Discord docs](https://github.com/Lulalaby/discord-api-docs/pull/30)
132153#[ cfg_attr( feature = "typesize" , derive( typesize:: derive:: TypeSize ) ) ]
133154#[ derive( Clone , Debug , Deserialize , Serialize ) ]
134155#[ non_exhaustive]
135156pub struct UnfurledMediaItem {
136157 url : FixedString < u16 > ,
137158}
138159
160+ /// A resolved unfurled media item, with extra metadata added by Discord.
161+ ///
162+ /// [Incomplete Discord docs](https://github.com/Lulalaby/discord-api-docs/pull/30)
139163#[ cfg_attr( feature = "typesize" , derive( typesize:: derive:: TypeSize ) ) ]
140164#[ derive( Clone , Debug , Deserialize , Serialize ) ]
141165#[ non_exhaustive]
@@ -162,6 +186,11 @@ enum_number! {
162186 }
163187}
164188
189+ /// A list of valid components for an accessory of a section.
190+ ///
191+ /// See [`Section`] for how this works.
192+ ///
193+ /// [Incomplete Discord docs](https://github.com/Lulalaby/discord-api-docs/pull/30)
165194#[ cfg_attr( feature = "typesize" , derive( typesize:: derive:: TypeSize ) ) ]
166195#[ derive( Clone , Debug , Serialize ) ]
167196#[ non_exhaustive]
@@ -177,29 +206,51 @@ impl_deserialize_component!(SectionAccessory,
177206 ComponentType :: Thumbnail => SectionAccessory :: Thumbnail
178207) ;
179208
209+ /// The valid components a section can contain.
210+ ///
211+ /// See [`Section`] for other details.
212+ ///
213+ /// [Incomplete Discord docs](https://github.com/Lulalaby/discord-api-docs/pull/30)
180214#[ cfg_attr( feature = "typesize" , derive( typesize:: derive:: TypeSize ) ) ]
181- #[ derive( Clone , Debug , Deserialize , Serialize ) ]
215+ #[ derive( Clone , Debug , Serialize ) ]
182216#[ non_exhaustive]
183217pub enum SectionComponent {
184218 TextDisplay ( TextDisplay ) ,
185219 Unknown ,
186- // TODO: check others because i'm rushing this.
187220}
188221
222+ impl_deserialize_component ! ( SectionComponent ,
223+ ComponentType :: TextDisplay => SectionComponent :: TextDisplay
224+ ) ;
225+
226+ /// A text display component.
227+ ///
228+ /// [Incomplete Discord docs](https://github.com/Lulalaby/discord-api-docs/pull/30)
189229#[ cfg_attr( feature = "typesize" , derive( typesize:: derive:: TypeSize ) ) ]
190230#[ derive( Clone , Debug , Deserialize , Serialize ) ]
191231#[ non_exhaustive]
192232pub struct TextDisplay {
193233 content : FixedString < u16 > ,
194234}
195235
236+ /// A media gallery component.
237+ ///
238+ /// [Incomplete Discord docs](https://github.com/Lulalaby/discord-api-docs/pull/30)
196239#[ cfg_attr( feature = "typesize" , derive( typesize:: derive:: TypeSize ) ) ]
197240#[ derive( Clone , Debug , Deserialize , Serialize ) ]
198241#[ non_exhaustive]
199242pub struct MediaGallery {
243+ /// Always [`ComponentType::MediaGallery`]
244+ #[ serde( rename = "type" ) ]
245+ pub kind : ComponentType ,
200246 items : FixedArray < MediaGalleryItem > ,
201247}
202248
249+ /// An individual media gallery item.
250+ ///
251+ /// Belongs to [`MediaGallery`].
252+ ///
253+ /// [Incomplete Discord docs](https://github.com/Lulalaby/discord-api-docs/pull/30)
203254#[ cfg_attr( feature = "typesize" , derive( typesize:: derive:: TypeSize ) ) ]
204255#[ derive( Clone , Debug , Deserialize , Serialize ) ]
205256#[ non_exhaustive]
@@ -209,15 +260,22 @@ pub struct MediaGalleryItem {
209260 spoiler : Option < bool > ,
210261}
211262
263+ /// A separator component
264+ ///
265+ /// [Incomplete Discord docs](https://github.com/Lulalaby/discord-api-docs/pull/30)
212266#[ cfg_attr( feature = "typesize" , derive( typesize:: derive:: TypeSize ) ) ]
213267#[ derive( Clone , Debug , Deserialize , Serialize ) ]
214268#[ non_exhaustive]
215269pub struct Separator {
270+ /// Always [`ComponentType::Separator`]
271+ #[ serde( rename = "type" ) ]
272+ pub kind : ComponentType ,
216273 divider : Option < bool > ,
217274 spacing : Option < SeparatorSpacingSize > ,
218275}
219276
220277enum_number ! {
278+ /// The size of a separator component.
221279 #[ derive( Clone , Copy , Debug , Eq , Hash , Ord , PartialEq , PartialOrd , Deserialize , Serialize ) ]
222280 #[ cfg_attr( feature = "typesize" , derive( typesize:: derive:: TypeSize ) ) ]
223281 #[ non_exhaustive]
@@ -228,18 +286,30 @@ enum_number! {
228286 }
229287}
230288
289+ /// A file component, will not render a text preview to the user.
290+ ///
291+ /// [Incomplete Discord docs](https://github.com/Lulalaby/discord-api-docs/pull/30)
231292#[ derive( Clone , Debug , Deserialize , Serialize ) ]
232293#[ cfg_attr( feature = "typesize" , derive( typesize:: derive:: TypeSize ) ) ]
233294#[ non_exhaustive]
234295pub struct FileComponent {
296+ /// Always [`ComponentType::File`]
297+ #[ serde( rename = "type" ) ]
298+ pub kind : ComponentType ,
235299 file : UnfurledMediaItem ,
236300 spoiler : Option < bool > ,
237301}
238302
303+ /// A container component, similar to an embed but without all the functionality.
304+ ///
305+ /// [Incomplete Discord docs](https://github.com/Lulalaby/discord-api-docs/pull/30)
239306#[ derive( Clone , Debug , Deserialize , Serialize ) ]
240307#[ cfg_attr( feature = "typesize" , derive( typesize:: derive:: TypeSize ) ) ]
241308#[ non_exhaustive]
242309pub struct Container {
310+ /// Always [`ComponentType::Container`]
311+ #[ serde( rename = "type" ) ]
312+ pub kind : ComponentType ,
243313 accent_color : Option < Colour > ,
244314 spoiler : Option < bool > ,
245315 components : FixedArray < Component > ,
0 commit comments