twilight_model/channel/message/component/
select_menu.rs1use crate::channel::{ChannelType, message::EmojiReactionType};
2use crate::id::Id;
3use crate::id::marker::{ChannelMarker, RoleMarker, UserMarker};
4use serde::{Deserialize, Serialize};
5
6#[derive(Clone, Debug, Eq, Hash, PartialEq)]
10pub struct SelectMenu {
11 pub channel_types: Option<Vec<ChannelType>>,
15 pub custom_id: String,
17 pub default_values: Option<Vec<SelectDefaultValue>>,
19 pub disabled: bool,
23 pub id: Option<i32>,
25 pub kind: SelectMenuType,
27 pub max_values: Option<u8>,
29 pub min_values: Option<u8>,
31 pub options: Option<Vec<SelectMenuOption>>,
35 pub placeholder: Option<String>,
37 pub required: Option<bool>,
41}
42
43#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
45#[non_exhaustive]
46pub enum SelectMenuType {
47 Channel,
49 Mentionable,
51 Role,
53 Text,
58 User,
60}
61
62#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
64pub struct SelectMenuOption {
65 #[serde(default)]
67 pub default: bool,
68 #[serde(skip_serializing_if = "Option::is_none")]
70 pub description: Option<String>,
71 #[serde(skip_serializing_if = "Option::is_none")]
74 pub emoji: Option<EmojiReactionType>,
75 pub label: String,
77 pub value: String,
79}
80
81#[derive(Copy, Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
83#[serde(tag = "type", content = "id", rename_all = "snake_case")]
84pub enum SelectDefaultValue {
85 Channel(Id<ChannelMarker>),
87 Role(Id<RoleMarker>),
89 User(Id<UserMarker>),
91}
92
93#[cfg(test)]
94mod tests {
95 use super::*;
96 use static_assertions::{assert_fields, assert_impl_all};
97 use std::{fmt::Debug, hash::Hash};
98
99 assert_fields!(
100 SelectMenu: channel_types,
101 custom_id,
102 default_values,
103 disabled,
104 id,
105 kind,
106 max_values,
107 min_values,
108 options,
109 placeholder,
110 required
111 );
112 assert_impl_all!(SelectMenu: Clone, Debug, Eq, Hash, PartialEq, Send, Sync);
113
114 assert_impl_all!(
115 SelectMenuType: Clone,
116 Debug,
117 Eq,
118 Hash,
119 PartialEq,
120 Send,
121 Sync
122 );
123
124 assert_impl_all!(
125 SelectMenuOption: Clone,
126 Debug,
127 Deserialize<'static>,
128 Eq,
129 Hash,
130 PartialEq,
131 Send,
132 Serialize,
133 Sync
134 );
135 assert_fields!(SelectMenuOption: default, description, emoji, label, value);
136
137 assert_impl_all!(
138 SelectDefaultValue: Copy,
139 Clone,
140 Debug,
141 Deserialize<'static>,
142 Eq,
143 Hash,
144 Ord,
145 PartialEq,
146 PartialOrd,
147 Serialize
148 );
149}