irc_rust/lib.rs
1#![deny(clippy::all)]
2#![deny(clippy::cargo)]
3
4//! This crate implements a simple irc message wrapper.
5//!
6//! This project has 2 goals:
7//!
8//! - Ease the access to fields of the message without requiring the user to handle offsets and other IRC related things.
9//! - Minimize memory foodprint. For this goal the `Message` struct only owns the `String` of the actual message. Any
10//! parts of the message and other structs only work on references of this string.
11//!
12//! Therefore this project expects the strings passed to the struct
13//! constructors to be valid parts of the IRC standard.
14//!
15//! As reference the [RFC2812](https://tools.ietf.org/html/rfc2812) and some extensions
16//! from [IRCv3](https://ircv3.net/) are used.
17//!
18//! # Support
19//!
20//! Current support (as of version '0.3.*'):
21//!
22//! - **Message**: Create read-only Message from `String` or `&str` and with a builder `Message::builder()`.
23//! - **Tags**: access through the indexing operator and iterating over all tags.
24//! - **Prefix**: Read-only access + Builder.
25//! - **Parameters List**: Read-only access, Iteration over elements, separate access to trailing parameter.
26//! - **Serde**: Serialization in any format supported by serde.
27//!
28//! # Examples - for starters
29//!
30//! Simple example with static string:
31//!
32//! ```rust
33//! use irc_rust::Message;
34//!
35//! let message = Message::from("@key1=value1;key2=value2 :name!user@host CMD param1 param2 :trailing");
36//!
37//! assert_eq!(message.to_string(), "@key1=value1;key2=value2 :name!user@host CMD param1 param2 :trailing");
38//! ```
39//!
40//! While reading from standard input the `Message::from` method has to be used.
41//!
42//! ```rust
43//! use irc_rust::Message;
44//! use std::io::{BufRead, stdin};
45//!
46//! # fn main() -> Result<(), irc_rust::errors::ParserError> {
47//! for line in stdin().lock().lines() {
48//! match line {
49//! Ok(line) => {
50//! let message = Message::from(line);
51//! println!("> Received command: {}", message.command()?);
52//! }
53//! Err(e) => {
54//! println!("got error; aborting: {}", e);
55//! break;
56//! }
57//! }
58//! }
59//! # Ok::<(), irc_rust::errors::ParserError>(())
60//! # }
61//! ```
62
63#[cfg(feature = "serde")]
64#[macro_use]
65extern crate serde;
66
67pub mod builder;
68pub mod errors;
69pub mod message;
70pub mod parsed;
71pub mod prefix;
72pub mod tokenizer;
73
74#[cfg(test)]
75mod test;
76
77pub use message::Message;