twilight_model/channel/message/component/
text_input.rs1use serde_repr::{Deserialize_repr, Serialize_repr};
2
3#[derive(Clone, Debug, Eq, Hash, PartialEq)]
7pub struct TextInput {
8 pub custom_id: String,
10 pub label: String,
12 pub max_length: Option<u16>,
14 pub min_length: Option<u16>,
18 pub placeholder: Option<String>,
20 pub required: Option<bool>,
24 pub style: TextInputStyle,
26 pub value: Option<String>,
28}
29
30#[derive(Clone, Copy, Debug, Deserialize_repr, Eq, Hash, PartialEq, Serialize_repr)]
32#[non_exhaustive]
33#[repr(u8)]
34pub enum TextInputStyle {
35 Short = 1,
37 Paragraph = 2,
39}
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44 use serde::{Deserialize, Serialize};
45 use serde_test::Token;
46 use static_assertions::{assert_fields, assert_impl_all, const_assert_eq};
47 use std::{fmt::Debug, hash::Hash};
48
49 assert_fields!(
50 TextInput: custom_id,
51 label,
52 style,
53 placeholder,
54 min_length,
55 max_length,
56 value
57 );
58 assert_impl_all!(TextInput: Clone, Debug, Eq, Hash, PartialEq, Send, Sync);
59
60 assert_impl_all!(
61 TextInputStyle: Clone,
62 Copy,
63 Debug,
64 Deserialize<'static>,
65 Eq,
66 Hash,
67 PartialEq,
68 Send,
69 Serialize,
70 Sync
71 );
72 const_assert_eq!(1, TextInputStyle::Short as u8);
73 const_assert_eq!(2, TextInputStyle::Paragraph as u8);
74
75 #[test]
76 fn text_input_style() {
77 serde_test::assert_tokens(&TextInputStyle::Short, &[Token::U8(1)]);
78 serde_test::assert_tokens(&TextInputStyle::Paragraph, &[Token::U8(2)]);
79 }
80}