[−][src]Struct irc_rust::message::Message
A simple irc message containing tags, prefix, command, parameters and a trailing parameter.
Examples
Create a Message from a plain string.
use irc_rust::message::Message; let message = Message::from("@key1=value1;key2=value2 :name!user@host CMD param1 param2 :trailing"); assert_eq!(message.to_string(), "@key1=value1;key2=value2 :name!user@host CMD param1 param2 :trailing");
To build a message in a verbose and easy to read way you can use the Message::builder
method and the MessageBuilder
.
use irc_rust::message::Message; let message = Message::builder() .tag("key1", "value1") .tag("key2", "value2") .prefix_name("name") .prefix_user("user") .prefix_host("host") .command("CMD") .param("param1").param("param2") .trailing("trailing") .build(); let tags = message.tags().unwrap(); println!("key1={}", &tags["key1"]) // Prints 'key1=value1'
You can create a new message from an existing message by calling the to_builder
method.
To alter existing parameters the set_param
method can be used.
use irc_rust::message::Message; let message = Message::from("@key=value :name!user@host CMD param1 :trailing!").to_builder() .tag("key", "value2") .param("param2") .param("param4") .set_param(1, "param3") .build(); assert_eq!(message.to_string(), "@key=value2 :name!user@host CMD param1 param3 param4 :trailing!");
Implementations
impl Message
[src]
pub fn new(raw: String) -> Message
[src]
Create a new Message from the given string. Expects the string to be in a valid irc format.
pub fn from(raw: &str) -> Message
[src]
pub fn builder<'a>() -> MessageBuilder<'a>
[src]
Creates a message builder as alternative to building an irc string before creating the message.
pub fn to_builder(&self) -> MessageBuilder
[src]
Creates a builder from this message. Only initializes fields already present in the message. By using this method a whole new Message will be created.
pub fn tags(&self) -> Option<Tags>
[src]
Returns tags if any are present.
pub fn prefix(&self) -> Option<Prefix>
[src]
Returns the Prefix if present.
pub fn command(&self) -> &str
[src]
Returns the command the message represents.
pub fn params(&self) -> Option<Params>
[src]
Returns the params if any are present.
Trait Implementations
impl Clone for Message
[src]
impl Debug for Message
[src]
impl<'de> Deserialize<'de> for Message
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl Display for Message
[src]
impl Serialize 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> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
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>,