reproto_semver/
errors.rs

1//! Errors for this crate.
2
3use parser;
4use std::error;
5use std::fmt;
6
7/// An error type for this crate.
8#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
9pub enum Error<'input> {
10    /// An error ocurred while parsing.
11    Parser(parser::Error<'input>),
12    /// Received more input than expected.
13    MoreInput,
14}
15
16impl<'input> fmt::Display for Error<'input> {
17    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
18        use self::Error::*;
19
20        match *self {
21            Parser(ref p) => write!(fmt, "parser error: {}", p),
22            MoreInput => write!(fmt, "more input"),
23        }
24    }
25}
26
27impl<'input> error::Error for Error<'input> {
28    fn description(&self) -> &str {
29        use self::Error::*;
30
31        match *self {
32            Parser(ref p) => p.description(),
33            MoreInput => "more input",
34        }
35    }
36}
37
38impl<'input> From<parser::Error<'input>> for Error<'input> {
39    fn from(value: parser::Error<'input>) -> Self {
40        Error::Parser(value)
41    }
42}