diff --git a/src/format.rs b/src/format.rs index a06edf5..5c896dd 100644 --- a/src/format.rs +++ b/src/format.rs @@ -19,7 +19,9 @@ fn tag_encode(input: &str) -> String { impl Line { #[allow(clippy::doc_markdown)] - /// Format `self` in to a byte string by [RFC1459] and [IRCv3] protocol rules. + /// Format `self` into a byte string by [RFC1459] and [IRCv3] protocol rules. + /// + /// The returned byte string is NOT suffixed with a CRLF. /// /// [RFC1459]: https://www.rfc-editor.org/rfc/rfc1459#section-2.3 /// [IRCv3]: https://ircv3.net/specs/extensions/message-tags.html diff --git a/src/lib.rs b/src/lib.rs index 02d1282..770cb5b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,16 @@ +//! ## usage +//! +//! ### tokenisation +//! +//! ``` +//! let bytes = b"@id=123 :jess!~jess@hostname PRIVMSG #chat :hello there!"; +//! let line = irctokens::Line::tokenise(bytes).unwrap(); +//! println!("{:?}", line.tags); +//! println!("{:?}", line.source); +//! println!("{}", line.command); +//! println!("{:?}", line.arguments); +//! ``` + mod format; mod obj; pub mod tokenise; diff --git a/src/tokenise.rs b/src/tokenise.rs index 036c606..55cbcad 100644 --- a/src/tokenise.rs +++ b/src/tokenise.rs @@ -7,15 +7,15 @@ const TAG_STOP: [&[u8]; 2] = [b"", b"="]; #[derive(Debug)] pub enum Error { - /// An empty byte array was passed to the tokeniser + /// An empty byte array was passed to the tokeniser. Empty, - /// A line is invalid if it has no `COMMAND` (e.g. `PRIVMSG`) + /// A line is invalid if it has no `COMMAND` (e.g. `PRIVMSG`). MissingCommand, - /// Commands must be ascii encoded + /// Commands must be ascii encoded. CommandDecode, - /// Message tag keys must be utf8 encoded + /// Message tag keys must be utf8 encoded. TagKeyDecode, - /// Message tag values must be utf8 encoded + /// Message tag values must be utf8 encoded. TagValueDecode, } @@ -50,6 +50,8 @@ impl Line { #[allow(clippy::doc_markdown)] /// Attempt to tokenise a byte string by [RFC1459] and [IRCv3] protocol rules. /// + /// Expects a byte string that does NOT contain a trailing CRLF. + /// /// [RFC1459]: https://www.rfc-editor.org/rfc/rfc1459#section-2.3 /// [IRCv3]: https://ircv3.net/specs/extensions/message-tags.html pub fn tokenise(mut line: &[u8]) -> Result { @@ -102,10 +104,10 @@ impl Line { } } +/// Implementation that simply calls [`Line::tokenise()`]. impl TryFrom<&[u8]> for Line { type Error = Error; - /// Utility function for [`Line::tokenise()`] fn try_from(value: &[u8]) -> Result { Self::tokenise(value) }