[−][src]Struct irc_proto::message::Message
A data structure representing an IRC message according to the protocol specification. It consists of a collection of IRCv3 tags, a prefix (describing the source of the message), and the protocol command. If the command is unknown, it is treated as a special raw command that consists of a collection of arguments and the special suffix argument. Otherwise, the command is parsed into a more useful form as described in Command.
Fields
Message tags as defined by IRCv3.2. These tags are used to add extended information to the given message, and are commonly used in IRCv3 extensions to the IRC protocol.
prefix: Option<Prefix>
The message prefix (or source) as defined by RFC 2812.
command: Command
The IRC command, parsed according to the known specifications. The command itself and its arguments (including the special suffix argument) are captured in this component.
Methods
impl Message
[src]
pub fn new(
prefix: Option<&str>,
command: &str,
args: Vec<&str>
) -> Result<Message, MessageParseError>
[src]
prefix: Option<&str>,
command: &str,
args: Vec<&str>
) -> Result<Message, MessageParseError>
Creates a new message from the given components.
Example
let message = Message::new( Some("nickname!username@hostname"), "JOIN", vec!["#channel"] ).unwrap();
pub fn with_tags(
tags: Option<Vec<Tag>>,
prefix: Option<&str>,
command: &str,
args: Vec<&str>
) -> Result<Message, MessageParseError>
[src]
tags: Option<Vec<Tag>>,
prefix: Option<&str>,
command: &str,
args: Vec<&str>
) -> Result<Message, MessageParseError>
Creates a new IRCv3.2 message from the given components, including message tags. These tags are used to add extended information to the given message, and are commonly used in IRCv3 extensions to the IRC protocol.
pub fn source_nickname(&self) -> Option<&str>
[src]
Gets the nickname of the message source, if it exists.
Example
let message = Message::new( Some("nickname!username@hostname"), "JOIN", vec!["#channel"] ).unwrap(); assert_eq!(message.source_nickname(), Some("nickname"));
pub fn response_target(&self) -> Option<&str>
[src]
Gets the likely intended place to respond to this message.
If the type of the message is a PRIVMSG
or NOTICE
and the message is sent to a channel,
the result will be that channel. In all other cases, this will call source_nickname
.
Example
let msg1 = Message::new( Some("ada"), "PRIVMSG", vec!["#channel", "Hi, everyone!"] ).unwrap(); assert_eq!(msg1.response_target(), Some("#channel")); let msg2 = Message::new( Some("ada"), "PRIVMSG", vec!["betsy", "betsy: hi"] ).unwrap(); assert_eq!(msg2.response_target(), Some("ada"));
pub fn to_string(&self) -> String
[src]
Converts a Message into a String according to the IRC protocol.
Example
let msg = Message::new( Some("ada"), "PRIVMSG", vec!["#channel", "Hi, everyone!"] ).unwrap(); assert_eq!(msg.to_string(), ":ada PRIVMSG #channel :Hi, everyone!\r\n");
Trait Implementations
impl Clone for Message
[src]
impl Debug for Message
[src]
impl Display for Message
[src]
impl Encoder<Message> for IrcCodec
[src]
type Error = ProtocolError
The type of encoding errors. Read more
fn encode(&mut self, msg: Message, dst: &mut BytesMut) -> Result<()>
[src]
impl<'a> From<&'a str> for Message
[src]
impl From<Command> for Message
[src]
impl FromStr for Message
[src]
type Err = ProtocolError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Message, Self::Err>
[src]
impl PartialEq<Message> for Message
[src]
impl StructuralPartialEq for Message
[src]
Auto Trait Implementations
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnwindSafe for Message
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> 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> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
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>,