Enum twilight_mention::parse::MentionType
source · #[non_exhaustive]pub enum MentionType {
Channel(Id<ChannelMarker>),
Emoji(Id<EmojiMarker>),
Role(Id<RoleMarker>),
Timestamp(Timestamp),
User(Id<UserMarker>),
}
Expand description
Any type of mention.
Contains variants for every possible kind of mention. Can be used with
ParseMention
and iterated over just like any other mention.
Examples
Parse any type of mention out of a string:
use twilight_mention::{
parse::{MentionType, ParseMention},
timestamp::Timestamp,
};
use twilight_model::id::{
marker::{ChannelMarker, RoleMarker, UserMarker},
Id,
};
assert_eq!(
MentionType::Channel(Id::<ChannelMarker>::new(123)),
MentionType::parse("<#123>")?,
);
assert_eq!(
MentionType::Role(Id::<RoleMarker>::new(123)),
MentionType::parse("<@&123>")?,
);
let timestamp = Timestamp::new(123, None);
assert_eq!(
MentionType::Timestamp(timestamp),
MentionType::parse("<t:123>")?
);
Iterate over all types of mentions in a buffer:
use twilight_mention::{
parse::{MentionType, ParseMention},
timestamp::Timestamp,
};
let buf = "channel <#12> emoji <:name:34> role <@&56> timestamp <t:1624047978> user <@78>";
let mut iter = MentionType::iter(buf);
assert!(matches!(iter.next(), Some((MentionType::Channel(channel), _, _)) if channel.get() == 12));
assert!(matches!(iter.next(), Some((MentionType::Emoji(emoji), _, _)) if emoji.get() == 34));
assert!(matches!(iter.next(), Some((MentionType::Role(role), _, _)) if role.get() == 56));
assert!(matches!(
iter.next(),
Some((MentionType::Timestamp(timestamp), _, _))
if timestamp.unix() == 1_624_047_978 && timestamp.style().is_none()
));
assert!(matches!(iter.next(), Some((MentionType::User(user), _, _)) if user.get() == 78));
assert!(iter.next().is_none());
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Channel(Id<ChannelMarker>)
Channel mention.
Emoji(Id<EmojiMarker>)
Emoji mention.
Role(Id<RoleMarker>)
Role mention.
Timestamp(Timestamp)
Timestamp mention.
User(Id<UserMarker>)
User mention.
Trait Implementations§
source§impl Clone for MentionType
impl Clone for MentionType
source§fn clone(&self) -> MentionType
fn clone(&self) -> MentionType
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for MentionType
impl Debug for MentionType
source§impl Display for MentionType
impl Display for MentionType
source§impl ParseMention for MentionType
impl ParseMention for MentionType
source§const SIGILS: &'static [&'static str] = _
const SIGILS: &'static [&'static str] = _
Sigils for any type of mention.
Contains all of the sigils of every other type of mention.
source§fn parse(buf: &str) -> Result<Self, ParseMentionError<'_>>where
Self: Sized,
fn parse(buf: &str) -> Result<Self, ParseMentionError<'_>>where Self: Sized,
Parse a mention from a string slice.
Examples
Returns ParseMentionErrorType::TimestampStyleInvalid
if a timestamp
style value is invalid.
source§impl PartialEq<MentionType> for MentionType
impl PartialEq<MentionType> for MentionType
source§fn eq(&self, other: &MentionType) -> bool
fn eq(&self, other: &MentionType) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.impl Copy for MentionType
impl Eq for MentionType
impl StructuralEq for MentionType
impl StructuralPartialEq for MentionType
Auto Trait Implementations§
impl RefUnwindSafe for MentionType
impl Send for MentionType
impl Sync for MentionType
impl Unpin for MentionType
impl UnwindSafe for MentionType
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more