twilight_model/guild/onboarding/
prompt_type.rsuse serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[non_exhaustive]
#[serde(from = "u8", into = "u8")]
pub enum OnboardingPromptType {
MultipleChoice,
Dropdown,
Unknown(u8),
}
impl OnboardingPromptType {
pub const fn kind(self) -> &'static str {
match self {
Self::MultipleChoice => "MultipleChoice",
Self::Dropdown => "DropDown",
Self::Unknown(_) => "Unknown",
}
}
}
impl From<u8> for OnboardingPromptType {
fn from(value: u8) -> Self {
match value {
0 => Self::MultipleChoice,
1 => Self::Dropdown,
unknown => Self::Unknown(unknown),
}
}
}
impl From<OnboardingPromptType> for u8 {
fn from(value: OnboardingPromptType) -> Self {
match value {
OnboardingPromptType::MultipleChoice => 0,
OnboardingPromptType::Dropdown => 1,
OnboardingPromptType::Unknown(unknown) => unknown,
}
}
}
#[cfg(test)]
mod tests {
use super::OnboardingPromptType;
use serde_test::{assert_tokens, Token};
#[test]
fn onboarding_prompt_type() {
const MAP: &[(OnboardingPromptType, u8, &str)] = &[
(OnboardingPromptType::MultipleChoice, 0, "MultipleChoice"),
(OnboardingPromptType::Dropdown, 1, "DropDown"),
(OnboardingPromptType::Unknown(3), 3, "Unknown"),
];
for (prompt_type, number, name) in MAP {
assert_eq!(prompt_type.kind(), *name);
assert_eq!(u8::from(*prompt_type), *number);
assert_eq!(OnboardingPromptType::from(*number), *prompt_type);
assert_tokens(number, &[Token::U8(*number)])
}
}
}