Struct irc_rust::Message[][src]

pub struct Message { /* fields omitted */ }

A simple irc message containing tags, prefix, command, parameters and a trailing parameter.

All types returned from getters of this type ([Prefix, Params, Tags]) are owned types. So they are tied to the Message instance they are retrieved from and don’t own their part of the message.

Parses its part lazily on method invokations.

Examples

Create a Message from a plain string.

use irc_rust::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;
use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
    let message = Message::builder("CMD")
        .tag("key1", "value1")
        .tag("key2", "value2")
        .prefix("name", Some("user"), Some("host"))
        .param("param1").param("param2")
        .trailing("trailing")
        .build();

    let tags = message.tags().unwrap().unwrap();
    println!("key1={}", &tags["key1"]); // Prints 'key1=value1'
    Ok(())
}

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;
use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
    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!");
    Ok(())
}

Implementations

impl Message[src]

pub fn builder(command: &str) -> MessageBuilder<'_>[src]

Creates a message builder as alternative to building an irc string before creating the message.

pub fn to_builder(&self) -> Result<MessageBuilder<'_>, InvalidIrcFormatError>[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) -> Result<Option<Tags<'_>>, InvalidIrcFormatError>[src]

Returns tags if any are present.

pub fn prefix(&self) -> Result<Option<Prefix<'_>>, InvalidIrcFormatError>[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 Display for Message[src]

impl Eq for Message[src]

impl From<&'_ str> for Message[src]

impl From<String> for Message[src]

impl Hash for Message[src]

impl Ord for Message[src]

impl PartialEq<Message> for Message[src]

impl PartialOrd<Message> for Message[src]

impl StructuralEq 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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.