[−][src]Struct ellidri::message::Message
An IRC message.
See Message::parse
for documentation on how to read IRC messages, and Buffer
for
how to create messages.
See the RFC 2812 for a complete description of IRC messages: https://tools.ietf.org/html/rfc2812.html#section-2.3.
Fields
The string containing all the tags.
Message tagging is an addition of an IRCv3 specification. Refer to the following page for more details on message tags: https://ircv3.net/specs/extensions/message-tags.
prefix: Option<&'a str>
The prefix of the message.
command: Result<Command, &'a str>
The command of the message.
It can either be a valid command in the form of Ok(Command::_)
, or a simple string.
Message::parse
sets this field to Err(_)
if the command is not a variant of Command
.
num_params: usize
The number of parameters, and the number of valid elements in Message::params
.
params: [&'a str; 15]
The actual parameters of the message.
Only the num_params
first elements are valid. Other elements are empty strings at the
time of writing.
Methods
impl<'a> Message<'a>
[src]
pub fn parse(s: &'a str) -> Option<Message<'a>>
[src]
Parses a string and returns information about the IRC message.
Relevant source of information: https://tools.ietf.org/html/rfc2812.html#section-2.3.
Examples
Here's an example of message parsing:
let privmsg = Message::parse(":ser PRIVMSG #fosdem :I'm Simon Sir\r\n").unwrap(); assert_eq!(privmsg.prefix, Some("ser")); assert_eq!(privmsg.command, Ok(Command::PrivMsg)); assert_eq!(privmsg.num_params, 2); assert_eq!(privmsg.params[0], "#fosdem"); assert_eq!(privmsg.params[1], "I'm Simon Sir");
If the command is unknown, it is stored as Err(command_string)
, where command_string
is
taken from the input string:
let unknown = Message::parse("Typo arg1\r\n").unwrap(); assert_eq!(unknown.prefix, None); assert_eq!(unknown.command, Err("Typo")); assert_eq!(unknown.num_params, 1); assert_eq!(unknown.params[0], "arg1");
Return value
Returns Some(msg)
when the message is correctly formed, None
otherwise.
let empty = Message::parse(" \r \n \t "); let no_command = Message::parse(":prefix"); assert!(empty.is_none()); assert!(no_command.is_none());
pub fn has_enough_params(&self) -> bool
[src]
Returns true if the message has enough parameters for its command.
Example
let nick = Message::parse("NICK hello there").unwrap(); assert_eq!(nick.has_enough_params(), true); let nick = Message::parse("NICK :").unwrap(); assert_eq!(nick.has_enough_params(), true); let nick = Message::parse("NICK").unwrap(); assert_eq!(nick.has_enough_params(), false);
Trait Implementations
Auto Trait Implementations
impl<'a> RefUnwindSafe for Message<'a>
impl<'a> Send for Message<'a>
impl<'a> Sync for Message<'a>
impl<'a> Unpin for Message<'a>
impl<'a> UnwindSafe for Message<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,