doge 0.1.0

A serde-based parser for DSON (Doge Serialized Object Notation)
Documentation
use serde;
use std;

pub type Result<T> = std::result::Result<T, Error>;

#[derive(Debug)]
pub enum Error {
    IO(std::io::Error),
    Message(String),
    TrailingChars,
    Eof,
    IncorrectType(&'static str, char),
    NumberSyntax,
}

impl serde::ser::Error for Error {
    fn custom<T: std::fmt::Display>(msg: T) -> Self {
        Error::Message(msg.to_string())
    }
}

impl serde::de::Error for Error {
    fn custom<T: std::fmt::Display>(msg: T) -> Self {
        Error::Message(msg.to_string())
    }
}

impl std::fmt::Display for Error {
    fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
        formatter.write_str(std::error::Error::description(self))
    }
}

impl std::error::Error for Error {
    fn description(&self) -> &str {
        match *self {
            Error::IO(ref err) => err.description(),
            Error::Message(ref msg) => msg,
            Error::TrailingChars => "trailing characters",
            Error::Eof => "unexpected end of input",
            Error::IncorrectType(ref _expected, ref _found) => "incorrect type found", // TODO somehow include the parameters
            Error::NumberSyntax => "failed to parse number",
        }
    }
}

impl From<std::io::Error> for Error {
    fn from(e: std::io::Error) -> Error {
        Error::IO(e)
    }
}