Struct irc::client::prelude::Message

source ·
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§

§tags: Option<Vec<Tag>>

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

source

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();
source

pub fn with_tags( 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.

source

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"));
source

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 Clone for Message

source§

fn clone(&self) -> Message

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Message

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Display for Message

source§

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<'a> From<&'a str> for Message

source§

fn from(s: &'a str) -> Message

Converts to this type from the input type.
source§

impl From<Command> for Message

source§

fn from(cmd: Command) -> Message

Converts to this type from the input type.
source§

impl FromStr for Message

§

type Err = ProtocolError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Message, <Message as FromStr>::Err>

Parses a string s to return a value of this type. Read more
source§

impl PartialEq for Message

source§

fn eq(&self, other: &Message) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Sink<Message> for Connection

§

type Error = Error

The type of value produced by the sink when an error occurs.
source§

fn poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Attempts to prepare the Sink to receive a value. Read more
source§

fn start_send(self: Pin<&mut Self>, item: Message) -> Result<(), Self::Error>

Begin the process of sending a value to the sink. Each call to this function must be preceded by a successful call to poll_ready which returned Poll::Ready(Ok(())). Read more
source§

fn poll_flush( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Flush any remaining output from this sink. Read more
source§

fn poll_close( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Flush any remaining output and close this sink, if necessary. Read more
source§

impl<T> Sink<Message> for Logged<T>
where T: Unpin + AsyncRead + AsyncWrite,

§

type Error = Error

The type of value produced by the sink when an error occurs.
source§

fn poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Attempts to prepare the Sink to receive a value. Read more
source§

fn poll_close( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Flush any remaining output and close this sink, if necessary. Read more
source§

fn start_send(self: Pin<&mut Self>, item: Message) -> Result<(), Self::Error>

Begin the process of sending a value to the sink. Each call to this function must be preceded by a successful call to poll_ready which returned Poll::Ready(Ok(())). Read more
source§

fn poll_flush( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Flush any remaining output from this sink. Read more
source§

impl<T> Sink<Message> for Transport<T>
where T: Unpin + AsyncRead + AsyncWrite,

§

type Error = Error

The type of value produced by the sink when an error occurs.
source§

fn poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Attempts to prepare the Sink to receive a value. Read more
source§

fn start_send(self: Pin<&mut Self>, item: Message) -> Result<(), Self::Error>

Begin the process of sending a value to the sink. Each call to this function must be preceded by a successful call to poll_ready which returned Poll::Ready(Ok(())). Read more
source§

fn poll_flush( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Flush any remaining output from this sink. Read more
source§

fn poll_close( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Flush any remaining output and close this sink, if necessary. Read more
source§

impl StructuralPartialEq for Message

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more