[][src]Module twilight_mention::parse

Parse mentions out of strings.

Included is a trait over select IDs that can be mentioned and an iterator to lazily parse mentions.

There is also the MentionType: it's an enum wrapping all possible types of mentions and works just like the individual IDs.

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.

Examples

Parse IDs out of strings that you know is just a mention:

use twilight_mention::ParseMention;
use twilight_model::id::{ChannelId, EmojiId, RoleId};

assert_eq!(EmojiId(123), EmojiId::parse("<:name:123>")?);
assert_eq!(RoleId(456), RoleId::parse("<@&456>")?);
assert!(ChannelId::parse("<#notamention>").is_err());

Iterate over the user mentions in a buffer:

use twilight_mention::ParseMention;
use twilight_model::id::UserId;

let mut iter = UserId::iter("these <@123> are <#456> mentions <@789>");
assert!(matches!(iter.next(), Some((UserId(123), _, _))));
assert!(matches!(iter.next(), Some((UserId(789), _, _))));
assert!(iter.next().is_none());

Structs

MentionIter

Iterator of mentions within a buffer.

Enums

MentionType

Any type of mention.

ParseMentionError

Parsing a mention failed due to invalid syntax.

Traits

ParseMention

Parse mentions out of buffers.