pub enum IRCPrefix {
HostOnly {
host: String,
},
Full {
nick: String,
user: Option<String>,
host: Option<String>,
},
}
Expand description
A “prefix” part of an IRC message, as defined by RFC 2812:
<prefix> ::= <servername> | <nick> [ '!' <user> ] [ '@' <host> ]
<servername> ::= <host>
<nick> ::= <letter> { <letter> | <number> | <special> }
<user> ::= <nonwhite> { <nonwhite> }
<host> ::= see RFC 952 [DNS:4] for details on allowed hostnames
<letter> ::= 'a' ... 'z' | 'A' ... 'Z'
<number> ::= '0' ... '9'
<special> ::= '-' | '[' | ']' | '\' | '`' | '^' | '{' | '}'
<nonwhite> ::= <any 8bit code except SPACE (0x20), NUL (0x0), CR
(0xd), and LF (0xa)>
§Examples
use twitch_irc::message::IRCPrefix;
use twitch_irc::message::AsRawIRC;
let prefix = IRCPrefix::Full {
nick: "a_nick".to_owned(),
user: Some("a_user".to_owned()),
host: Some("a_host.com".to_owned())
};
assert_eq!(prefix.as_raw_irc(), "a_nick!a_user@a_host.com");
use twitch_irc::message::IRCPrefix;
use twitch_irc::message::AsRawIRC;
let prefix = IRCPrefix::Full {
nick: "a_nick".to_owned(),
user: None,
host: Some("a_host.com".to_owned())
};
assert_eq!(prefix.as_raw_irc(), "a_nick@a_host.com");
use twitch_irc::message::IRCPrefix;
use twitch_irc::message::AsRawIRC;
let prefix = IRCPrefix::HostOnly {
host: "a_host.com".to_owned()
};
assert_eq!(prefix.as_raw_irc(), "a_host.com");
Variants§
HostOnly
The prefix specifies only a sending server/hostname.
Note that the spec also allows a very similar format where only a sending nickname is
specified. However that type of format plays no role on Twitch, and is practically impossible
to reliably tell apart from host-only prefix messages. For this reason, a prefix without
a @
character is always assumed to be purely a host-only prefix, and not a nickname-only prefix.
Full
The prefix variant specifies a nickname, and optionally also a username and optionally a hostname. See above for the RFC definition.
Implementations§
Source§impl IRCPrefix
impl IRCPrefix
Sourcepub fn parse(source: &str) -> IRCPrefix
pub fn parse(source: &str) -> IRCPrefix
Parse the IRCPrefix
from the given string slice. source
should be specified without
the leading :
that precedes in full IRC messages.
§Examples
use twitch_irc::message::IRCPrefix;
let prefix = IRCPrefix::parse("a_nick!a_user@a_host.com");
assert_eq!(prefix, IRCPrefix::Full {
nick: "a_nick".to_owned(),
user: Some("a_user".to_owned()),
host: Some("a_host.com".to_owned())
})
use twitch_irc::message::IRCPrefix;
let prefix = IRCPrefix::parse("a_host.com");
assert_eq!(prefix, IRCPrefix::HostOnly {
host: "a_host.com".to_owned()
})
Trait Implementations§
Source§impl<'de> Deserialize<'de> for IRCPrefix
impl<'de> Deserialize<'de> for IRCPrefix
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for IRCPrefix
impl StructuralPartialEq for IRCPrefix
Auto Trait Implementations§
impl Freeze for IRCPrefix
impl RefUnwindSafe for IRCPrefix
impl Send for IRCPrefix
impl Sync for IRCPrefix
impl Unpin for IRCPrefix
impl UnwindSafe for IRCPrefix
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more