[−][src]Trait twilight_mention::parse::ParseMention
Parse mentions out of buffers.
While the syntax of mentions will be validated and the IDs within them parsed, they won't be validated as being proper snowflakes or as real IDs in use.
Note that this trait is sealed and is not meant to be manually implemented.
Associated Constants
pub const SIGILS: &'static [&'static str]
[src]
Leading sigil(s) of the mention after the leading arrow (<
).
In a channel mention, the sigil is #
. In the case of a user mention,
the sigil may be either @
or @!
.
Required methods
pub fn parse(buf: &str) -> Result<Self, ParseMentionError<'_>> where
Self: Sized,
[src]
Self: Sized,
Parse a mention out of a buffer.
This will not search the buffer for a mention and will instead treat the entire buffer as a mention.
Examples
use twilight_mention::ParseMention; use twilight_model::id::{ChannelId, UserId}; assert_eq!(ChannelId(123), ChannelId::parse("<#123>")?); assert_eq!(UserId(456), UserId::parse("<@456>")?); assert!(ChannelId::parse("not a mention").is_err());
Errors
Returns ParseMentionError::LeadingArrow
if the leading arrow is not
present.
Returns ParseMentionError::Sigil
if the mention type's sigil is not
present after the leading arrow.
Returns ParseMentionError::TrailingArrow
if the trailing arrow is
not present after the ID.
Provided methods
#[must_use = "you must use the iterator to lazily parse mentions"]pub fn iter(buf: &str) -> MentionIter<'_, Self>ⓘNotable traits for MentionIter<'a, T>
impl<'a, T: ParseMention + Debug> Iterator for MentionIter<'a, T> type Item = (T, usize, usize);
where
Self: Sized,
[src]
Notable traits for MentionIter<'a, T>
impl<'a, T: ParseMention + Debug> Iterator for MentionIter<'a, T> type Item = (T, usize, usize);
Self: Sized,
Search a buffer for mentions and parse out any that are encountered.
Unlike parse
, this will not error if anything that is indicative of
a mention is encountered but did not successfully parse, such as a <
but with no trailing mention sigil.
Implementations on Foreign Types
impl ParseMention for ChannelId
[src]
pub const SIGILS: &'static [&'static str]
[src]
pub fn parse(buf: &str) -> Result<Self, ParseMentionError<'_>> where
Self: Sized,
[src]
Self: Sized,
impl ParseMention for EmojiId
[src]
pub const SIGILS: &'static [&'static str]
[src]
pub fn parse(buf: &str) -> Result<Self, ParseMentionError<'_>> where
Self: Sized,
[src]
Self: Sized,
impl ParseMention for RoleId
[src]
pub const SIGILS: &'static [&'static str]
[src]
pub fn parse(buf: &str) -> Result<Self, ParseMentionError<'_>> where
Self: Sized,
[src]
Self: Sized,
impl ParseMention for UserId
[src]
pub const SIGILS: &'static [&'static str]
[src]
Sigils for User ID mentions.
Unlike other IDs, user IDs have two possible sigils: @!
and @
.
pub fn parse(buf: &str) -> Result<Self, ParseMentionError<'_>> where
Self: Sized,
[src]
Self: Sized,