pub fn parse(text: &str) -> Result<VecDeque<Line>, ParseError>
Expand description
Parses an IRC message.
§Arguments
text
- The text you want to parse. This can comprise of multiple lines. In this case, each line (separated by a newline character) will be a separate element in the return value.
§Returns
VecDeque<Line>
- AVecDeque
of all parsedLine
s. This will be empty if no valid lines were passed and no errors occur.
§Example
let msg = "@id=123;name=rick :nick!user@host.tmi.twitch.tv PRIVMSG #rickastley :Never gonna give you up!\r\n";
match ircparser::parse(msg) {
Ok(mut x) => {
let line = x.pop_front().unwrap();
assert_eq!(&line.tags["id"], "123");
if line.source.is_some() {
assert_eq!(line.source.unwrap(), ":nick!user@host.tmi.twitch.tv");
}
assert_eq!(line.command, "PRIVMSG");
assert_eq!(line.params[0], "#rickastley");
assert_eq!(line.params[1], "Never gonna give you up!");
}
Err(e) => {
println!("A parsing error occured: {e}");
return;
}
};
§Notice
The behaviour of this function changed in v0.2.0. It can now accept
multiple lines at once, but as a consequence, now returns a
VecDeque
of Line
objects instead of a single Line
.