1use nom::error::Error;
2
3pub type ParseResult<'a, T> = Result<T, SyslogParseError<'a>>;
4pub type NomErrorKind = nom::error::ErrorKind;
5pub type NomError<'a> = nom::Err<Error<&'a str>>;
6
7#[derive(Error, Debug)]
8pub enum SyslogParseError<'a> {
9 #[error("parse {0}: {1}")]
10 ParseError0(&'a str, nom::Err<Error<&'a str>>),
11
12 #[error("parse {0}: {1}")]
13 ParseError1(&'a str, ErrorKind),
14
15 #[error("时间格式不符合,期待1985-04-12T23:20:50.52Z、1985-04-12T19:20:50.52-04:00、2003-10-11T22:14:15.003Z等")]
16 TimeParseError,
17}
18
19#[derive(Debug, Display)]
20pub enum ErrorKind {
21 #[strum(serialize = "优先级格式不符合,希望facility范围:0-23,severity范围:0-7")]
22 Pri,
23 #[strum(
24 serialize = "时间格式不符合,期待1985-04-12T23:20:50.52Z、1985-04-12T19:20:50.52-04:00、2003-10-11T22:14:15.003Z等"
25 )]
26 Timestamp,
27 #[strum(serialize = "Hostname格式不符合, IPV4遵循RFC1035,IPV6遵循RFC4291")]
28 Hostname,
29 #[strum(serialize = "Appname格式不符合")]
30 Appname,
31 #[strum(serialize = "Process Id格式不符合")]
32 ProcessId,
33 #[strum(serialize = "Message Id格式不符合")]
34 MessageId,
35}
36
37pub trait New {
38 #[allow(clippy::new_ret_no_self)]
39 fn new(input: &str, code: nom::error::ErrorKind) -> NomError {
40 nom::Err::Error(Error::new(input, code))
41 }
42}
43
44impl New for NomError<'_> {}