pub struct Message {
pub tags: Option<Vec<Tag>>,
pub prefix: Option<Prefix>,
pub command: Command,
}
Expand description
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.
Implementations§
source§impl Message
impl Message
sourcepub fn new(
prefix: Option<&str>,
command: &str,
args: Vec<&str>
) -> Result<Message, MessageParseError>
pub fn new( 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();
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.
sourcepub fn source_nickname(&self) -> Option<&str>
pub fn source_nickname(&self) -> Option<&str>
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"));
sourcepub fn response_target(&self) -> Option<&str>
pub fn response_target(&self) -> Option<&str>
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"));
Trait Implementations§
source§impl Display for Message
impl Display for Message
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
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");
source§impl PartialEq for Message
impl PartialEq for Message
source§impl Sink<Message> for Connection
impl Sink<Message> for Connection
source§fn poll_ready(
self: Pin<&mut Self>,
cx: &mut Context<'_>
) -> Poll<Result<(), Self::Error>>
fn poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>
Sink
to receive a value. Read moresource§fn start_send(self: Pin<&mut Self>, item: Message) -> Result<(), Self::Error>
fn start_send(self: Pin<&mut Self>, item: Message) -> Result<(), Self::Error>
poll_ready
which returned Poll::Ready(Ok(()))
. Read moresource§impl<T> Sink<Message> for Logged<T>
impl<T> Sink<Message> for Logged<T>
source§fn poll_ready(
self: Pin<&mut Self>,
cx: &mut Context<'_>
) -> Poll<Result<(), Self::Error>>
fn poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>
Sink
to receive a value. Read moresource§fn poll_close(
self: Pin<&mut Self>,
cx: &mut Context<'_>
) -> Poll<Result<(), Self::Error>>
fn poll_close( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>
source§impl<T> Sink<Message> for Transport<T>
impl<T> Sink<Message> for Transport<T>
source§fn poll_ready(
self: Pin<&mut Self>,
cx: &mut Context<'_>
) -> Poll<Result<(), Self::Error>>
fn poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>
Sink
to receive a value. Read moresource§fn start_send(self: Pin<&mut Self>, item: Message) -> Result<(), Self::Error>
fn start_send(self: Pin<&mut Self>, item: Message) -> Result<(), Self::Error>
poll_ready
which returned Poll::Ready(Ok(()))
. Read more