[][src]Trait twilight_mention::parse::ParseMention

pub trait ParseMention: Sealed {
    pub const SIGILS: &'static [&'static str];

    pub fn parse(buf: &str) -> Result<Self, ParseMentionError<'_>>
    where
        Self: Sized
; #[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
, { ... } }

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 @!.

Loading content...

Required methods

pub fn parse(buf: &str) -> Result<Self, ParseMentionError<'_>> where
    Self: Sized
[src]

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.

Loading content...

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]

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.

Loading content...

Implementations on Foreign Types

impl ParseMention for ChannelId[src]

impl ParseMention for EmojiId[src]

impl ParseMention for RoleId[src]

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 @.

Loading content...

Implementors

impl ParseMention for MentionType[src]

pub const SIGILS: &'static [&'static str][src]

Sigils for any type of mention.

Contains all of the sigils of every other type of mention.

Loading content...