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 id: Option<i32>,
10 pub custom_id: String,
12 #[deprecated = "Deprecated by Discord in favor of label and description on the Label component."]
14 pub label: Option<String>,
15 pub max_length: Option<u16>,
17 pub min_length: Option<u16>,
21 pub placeholder: Option<String>,
23 pub required: Option<bool>,
27 pub style: TextInputStyle,
29 pub value: Option<String>,
31}
32
33#[derive(Clone, Copy, Debug, Deserialize_repr, Eq, Hash, PartialEq, Serialize_repr)]
35#[non_exhaustive]
36#[repr(u8)]
37pub enum TextInputStyle {
38 Short = 1,
40 Paragraph = 2,
42}
43
44#[cfg(test)]
45#[allow(deprecated)]
46mod tests {
47 use super::*;
48 use serde::{Deserialize, Serialize};
49 use serde_test::Token;
50 use static_assertions::{assert_fields, assert_impl_all, const_assert_eq};
51 use std::{fmt::Debug, hash::Hash};
52
53 assert_fields!(
54 TextInput: custom_id,
55 label,
56 style,
57 placeholder,
58 min_length,
59 max_length,
60 value
61 );
62 assert_impl_all!(TextInput: Clone, Debug, Eq, Hash, PartialEq, Send, Sync);
63
64 assert_impl_all!(
65 TextInputStyle: Clone,
66 Copy,
67 Debug,
68 Deserialize<'static>,
69 Eq,
70 Hash,
71 PartialEq,
72 Send,
73 Serialize,
74 Sync
75 );
76 const_assert_eq!(1, TextInputStyle::Short as u8);
77 const_assert_eq!(2, TextInputStyle::Paragraph as u8);
78
79 #[test]
80 fn text_input_style() {
81 serde_test::assert_tokens(&TextInputStyle::Short, &[Token::U8(1)]);
82 serde_test::assert_tokens(&TextInputStyle::Paragraph, &[Token::U8(2)]);
83 }
84}