[][src]Enum twitch_irc::message::IRCPrefix

pub enum IRCPrefix {
    HostOnly {
        host: String,
    },
    Full {
        nick: String,
        user: Option<String>,
        host: Option<String>,
    },
}

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.

Fields of HostOnly

host: String

host part of the prefix

Full

The prefix variant specifies a nickname, and optionally also a username and optionally a hostname. See above for the RFC definition.

Fields of Full

nick: String

nick part of the prefix

user: Option<String>

user part of the prefix

host: Option<String>

host part of the prefix

Implementations

impl IRCPrefix[src]

pub fn parse(source: &str) -> IRCPrefix[src]

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

impl AsRawIRC for IRCPrefix[src]

impl Clone for IRCPrefix[src]

impl Debug for IRCPrefix[src]

impl Hash for IRCPrefix[src]

impl PartialEq<IRCPrefix> for IRCPrefix[src]

impl StructuralPartialEq for IRCPrefix[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,