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