twilight_model/poll/
layout_type.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
4#[non_exhaustive]
5#[serde(from = "u8", into = "u8")]
6pub enum PollLayoutType {
8 Default,
10 Unknown(u8),
12}
13
14impl From<u8> for PollLayoutType {
15 fn from(value: u8) -> Self {
16 match value {
17 1 => PollLayoutType::Default,
18 unknown => PollLayoutType::Unknown(unknown),
19 }
20 }
21}
22
23impl From<PollLayoutType> for u8 {
24 fn from(value: PollLayoutType) -> Self {
25 match value {
26 PollLayoutType::Default => 1,
27 PollLayoutType::Unknown(unknown) => unknown,
28 }
29 }
30}
31
32impl PollLayoutType {
33 pub const fn name(&self) -> &str {
34 match self {
35 PollLayoutType::Default => "Default",
36 PollLayoutType::Unknown(_) => "Unknown",
37 }
38 }
39}
40
41#[cfg(test)]
42mod tests {
43 use super::PollLayoutType;
44 use serde_test::Token;
45
46 #[test]
47 fn variants() {
48 serde_test::assert_tokens(&PollLayoutType::Default, &[Token::U8(1)]);
49 serde_test::assert_tokens(&PollLayoutType::Unknown(2), &[Token::U8(2)]);
50 }
51
52 #[test]
53 fn names() {
54 assert_eq!(PollLayoutType::Default.name(), "Default");
55 assert_eq!(PollLayoutType::Unknown(2).name(), "Unknown");
56 }
57}