twilight_model/channel/message/component/
text_input.rsuse 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)]);
}
}