twilight_model/channel/message/sticker/
kind.rsuse serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[non_exhaustive]
#[serde(from = "u8", into = "u8")]
pub enum StickerType {
Standard,
Guild,
Unknown(u8),
}
impl From<u8> for StickerType {
fn from(value: u8) -> Self {
match value {
1 => StickerType::Standard,
2 => StickerType::Guild,
unknown => StickerType::Unknown(unknown),
}
}
}
impl From<StickerType> for u8 {
fn from(value: StickerType) -> Self {
match value {
StickerType::Standard => 1,
StickerType::Guild => 2,
StickerType::Unknown(unknown) => unknown,
}
}
}
#[cfg(test)]
mod tests {
use super::StickerType;
use serde_test::Token;
#[test]
fn variants() {
serde_test::assert_tokens(&StickerType::Standard, &[Token::U8(1)]);
serde_test::assert_tokens(&StickerType::Guild, &[Token::U8(2)]);
serde_test::assert_tokens(&StickerType::Unknown(99), &[Token::U8(99)]);
}
#[test]
fn conversions() {
assert_eq!(StickerType::from(1), StickerType::Standard);
assert_eq!(StickerType::from(2), StickerType::Guild);
assert_eq!(StickerType::from(99), StickerType::Unknown(99));
}
}