#[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

source§

fn clone(&self) -> MentionType

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for MentionType

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for MentionType

source§

fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult

Formats the value using the given formatter. Read more
source§

impl ParseMention for MentionType

source§

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,

Parse a mention from a string slice.

Examples

Returns ParseMentionErrorType::TimestampStyleInvalid if a timestamp style value is invalid.

source§

fn iter(buf: &str) -> MentionIter<'_, Self> where Self: Sized,

Search a buffer for mentions and parse out any that are encountered. Read more
source§

impl PartialEq<MentionType> for MentionType

source§

fn eq(&self, other: &MentionType) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for MentionType

source§

impl Eq for MentionType

source§

impl StructuralEq for MentionType

source§

impl StructuralPartialEq for MentionType

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.