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§
Required Methods§
sourcefn parse(buf: &str) -> Result<Self, ParseMentionError<'_>>where
Self: Sized,
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§
sourcefn iter(buf: &str) -> MentionIter<'_, Self> ⓘwhere
Self: Sized,
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.