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
impl Message
Sourcepub fn parse(&self) -> Result<Parsed<'_>, ParserError>
pub fn parse(&self) -> Result<Parsed<'_>, ParserError>
Returns a fully parsed but zero-copy struct referencing the parsed message.
Sourcepub fn parse_partial<'a>(
&'a self,
cfg: PartialCfg<'a>,
) -> Result<Parsed<'a>, ParserError>
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));
Sourcepub fn tokenizer(&self) -> Result<Tokenizer<'_, Start>, ParserError>
pub fn tokenizer(&self) -> Result<Tokenizer<'_, Start>, ParserError>
Returns a tokenizer over the message. Can be used to implement a custom parsing algorithm.
Sourcepub fn builder(command: &str) -> MessageBuilder
pub fn builder(command: &str) -> MessageBuilder
Creates a message builder as alternative to building an irc string before creating the message.
Sourcepub fn to_builder(&self) -> Result<MessageBuilder, ParserError>
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.
Returns tags if any are present.
Sourcepub fn command(&self) -> Result<&str, ParserError>
pub fn command(&self) -> Result<&str, ParserError>
Returns the command the message represents.