Add some basic trait impls for Line and Error
This commit is contained in:
parent
7f2e0640d3
commit
e59b6b8c93
|
@ -3,7 +3,7 @@ use std::collections::BTreeMap;
|
|||
/// A struct representing all the constituent pieces of an RFC1459/IRCv3 protocol line.
|
||||
///
|
||||
/// `@tagkey=tagvalue :source COMMAND arg1 arg2 :arg3 with space`
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub struct Line {
|
||||
/// [Message tags] of an IRC line.
|
||||
/// [`None`] if no message tags were present.
|
||||
|
|
|
@ -5,7 +5,7 @@ use super::Line;
|
|||
|
||||
const TAG_STOP: [&[u8]; 2] = [b"", b"="];
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
pub enum Error {
|
||||
/// An empty byte array was passed to the tokeniser.
|
||||
Empty,
|
||||
|
@ -19,6 +19,20 @@ pub enum Error {
|
|||
TagValueDecode,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Error::Empty => write!(f, "empty slice passed to tokeniser"),
|
||||
Error::MissingCommand => write!(f, "missing command"),
|
||||
Error::CommandDecode => write!(f, "commands must be ascii encoded"),
|
||||
Error::TagKeyDecode => write!(f, "message tag keys must be utf8 encoded"),
|
||||
Error::TagValueDecode => write!(f, "message tag values must be utf8 encoded"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for Error {}
|
||||
|
||||
fn tag_decode(input: &str) -> String {
|
||||
let mut escaped = false;
|
||||
let mut output = String::with_capacity(input.len());
|
||||
|
|
Loading…
Reference in New Issue