Trait twilight_mention::parse::ParseMention

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

    // Required method
    fn parse(buf: &str) -> Result<Self, ParseMentionError<'_>>
       where Self: Sized;

    // Provided method
    fn iter(buf: &str) -> MentionIter<'_, Self> 
       where Self: Sized { ... }
}
Expand description

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.

Required Associated Constants§

source

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

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

Required Methods§

source

fn parse(buf: &str) -> Result<Self, ParseMentionError<'_>>
where 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::{
    marker::{ChannelMarker, UserMarker},
    Id,
};

assert_eq!(Id::<ChannelMarker>::new(123), Id::parse("<#123>")?,);
assert_eq!(Id::<UserMarker>::new(456), Id::parse("<@456>")?,);
assert!(Id::<ChannelMarker>::parse("not a mention").is_err());
§Errors

Returns a ParseMentionErrorType::LeadingArrow error type if the leading arrow is not present.

Returns a ParseMentionErrorType::Sigil error type if the mention type’s sigil is not present after the leading arrow.

Returns a ParseMentionErrorType::TrailingArrow error type if the trailing arrow is not present after the ID.

Provided Methods§

source

fn iter(buf: &str) -> MentionIter<'_, Self>
where 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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl ParseMention for Id<ChannelMarker>

source§

const SIGILS: &'static [&'static str] = _

source§

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

source§

impl ParseMention for Id<EmojiMarker>

source§

const SIGILS: &'static [&'static str] = _

source§

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

source§

impl ParseMention for Id<RoleMarker>

source§

const SIGILS: &'static [&'static str] = _

source§

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

source§

impl ParseMention for Id<UserMarker>

source§

const SIGILS: &'static [&'static str] = _

Sigil for User ID mentions.

source§

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

Implementors§

source§

impl ParseMention for CommandMention

source§

const SIGILS: &'static [&'static str] = _

source§

impl ParseMention for MentionType

source§

const SIGILS: &'static [&'static str] = _

source§

impl ParseMention for Timestamp

source§

const SIGILS: &'static [&'static str] = _