ncalendar

Reimplementation of the BSD calendar(1) program in Rust

git clone https://git.8pit.net/ncalendar.git

 1use std::io;
 2use std::str;
 3
 4#[derive(Debug)]
 5pub enum Error {
 6    IncompleteParse,
 7    EncodingError(str::Utf8Error),
 8    ParsingError(String, nom::error::ErrorKind),
 9    IoError(io::Error),
10}
11
12impl From<nom::Err<nom::error::Error<&str>>> for Error {
13    fn from(e: nom::Err<nom::error::Error<&str>>) -> Self {
14        match e {
15            nom::Err::Incomplete(_) => Error::IncompleteParse,
16            nom::Err::Error(e) | nom::Err::Failure(e) => {
17                Error::ParsingError(e.input.to_string(), e.code)
18            }
19        }
20    }
21}
22
23impl From<io::Error> for Error {
24    fn from(e: io::Error) -> Self {
25        Error::IoError(e)
26    }
27}
28
29impl From<str::Utf8Error> for Error {
30    fn from(e: str::Utf8Error) -> Self {
31        Error::EncodingError(e)
32    }
33}