pub(crate) mod delete_reaction;
mod create_reaction;
mod delete_all_reaction;
mod delete_all_reactions;
mod get_reactions;
pub use self::{
create_reaction::CreateReaction, delete_all_reaction::DeleteAllReaction,
delete_all_reactions::DeleteAllReactions, delete_reaction::DeleteReaction,
get_reactions::GetReactions,
};
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
use std::fmt::{Display, Formatter, Result as FmtResult};
use twilight_model::id::{marker::EmojiMarker, Id};
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum RequestReactionType<'a> {
Custom {
id: Id<EmojiMarker>,
name: Option<&'a str>,
},
Unicode {
name: &'a str,
},
}
impl Display for RequestReactionType<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
match self {
RequestReactionType::Custom { id, name } => {
if let Some(name) = name {
f.write_str(name)?;
} else {
f.write_str("e")?;
}
f.write_str(":")?;
Display::fmt(id, f)
}
RequestReactionType::Unicode { name } => {
Display::fmt(&utf8_percent_encode(name, NON_ALPHANUMERIC), f)
}
}
}
}
#[cfg(test)]
mod tests {
#![allow(clippy::non_ascii_literal)]
use super::RequestReactionType;
use static_assertions::{assert_fields, assert_impl_all};
use std::{
fmt::{Debug, Display},
hash::Hash,
};
use twilight_model::id::Id;
assert_fields!(RequestReactionType::Custom: id, name);
assert_fields!(RequestReactionType::Unicode: name);
assert_impl_all!(RequestReactionType<'_>: Clone, Copy, Debug, Display, Eq, Hash, PartialEq, Send, Sync);
#[test]
fn display_custom_with_name() {
let reaction = RequestReactionType::Custom {
id: Id::new(123),
name: Some("foo"),
};
assert_eq!("foo:123", reaction.to_string());
}
#[test]
fn display_custom_without_name() {
let reaction = RequestReactionType::Custom {
id: Id::new(123),
name: None,
};
assert_eq!("e:123", reaction.to_string());
}
#[test]
fn display_unicode() {
let reaction = RequestReactionType::Unicode {
name: "🏳️🌈",
};
assert_eq!(
"%F0%9F%8F%B3%EF%B8%8F%E2%80%8D%F0%9F%8C%88",
reaction.to_string()
);
}
}