Struct Message

Source
pub struct Message { /* private fields */ }
Expand description

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

// Or

let message = "@key1=value1;key2=value2 :name!user@host CMD param1 param2 :trailing"
    .parse::<Message>()?;

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.

Implementations§

Source§

impl Message

Source

pub fn parse(&self) -> Result<Parsed<'_>, ParserError>

Returns a fully parsed but zero-copy struct referencing the parsed message.

Source

pub fn parse_partial<'a>( &'a self, cfg: PartialCfg<'a>, ) -> Result<Parsed<'a>, ParserError>

Returns a query instance to partially parse the message.

§Usage
use irc_rust::Message;
use irc_rust::tokenizer::PartialCfg;
use std::collections::HashSet;
use std::iter::FromIterator;
let message = "@tag1=value1;tag2=value2 CMD param0 param1 :trailing"
    .parse::<Message>()?;
let parsed = message.parse_partial(PartialCfg {
        tags: HashSet::from_iter(vec!["tag2"]),
        params: vec![1],
        trailing: true,
        ..PartialCfg::default()
    })?;
assert_eq!(Some("CMD"), parsed.command());
assert!(parsed.tag("tag1").is_none());
assert!(parsed.prefix().is_none());
assert_eq!(Some("value2"), parsed.tag("tag2"));
assert_eq!(Some("param1"), parsed.param(1));
Source

pub fn tokenizer(&self) -> Result<Tokenizer<'_, Start>, ParserError>

Returns a tokenizer over the message. Can be used to implement a custom parsing algorithm.

Source

pub fn builder(command: &str) -> MessageBuilder

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

Source

pub fn to_builder(&self) -> Result<MessageBuilder, ParserError>

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.

Source

pub fn tags( &self, ) -> Result<impl Iterator<Item = Result<(&str, &str), ParserError>>, ParserError>

Returns tags if any are present.

Source

pub fn prefix(&self) -> Result<Option<Prefix<'_>>, ParserError>

Returns the Prefix if present.

Source

pub fn command(&self) -> Result<&str, ParserError>

Returns the command the message represents.

Source

pub fn params(&self) -> Result<impl Iterator<Item = &str>, ParserError>

Returns the params if any are present.

Source

pub fn trailing(&self) -> Result<Option<&str>, ParserError>

Returns the trailing parameter if any is present.

Trait Implementations§

Source§

impl Clone for Message

Source§

fn clone(&self) -> Message

Returns a duplicate 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

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

impl Display for Message

Source§

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

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

impl From<&str> for Message

Source§

fn from(raw: &str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Message

Source§

fn from(raw: String) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Message

Source§

type Err = ParserError

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

fn from_str(s: &str) -> Result<Self, Self::Err>

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

impl Hash for Message

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Message

Source§

fn cmp(&self, other: &Message) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Message

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Message

Source§

fn partial_cmp(&self, other: &Message) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl TryFrom<Message> for Builder

Source§

type Error = ParserError

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

fn try_from(value: Message) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for Message

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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,

Source§

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§

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>,

Source§

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>,

Source§

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.