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