valid_toml 0.0.2

Provides the ability to load a TOML file with validation.
Documentation
/* Copyright 2016 Joshua Gentry
 *
 * Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
 * http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
 * <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 * option. This file may not be copied, modified, or distributed
 * except according to those terms.
 */
use std::fmt::{self, Display, Formatter};
use std::io;

use enums::ValidationError;

//*************************************************************************************************
/// This enumeration identifies various errors that may occur when reading a TOML file.
#[derive(Debug)]
pub enum Error
{
    //---------------------------------------------------------------------------------------------
    /// There was a problem accessing the file.
    FileError(io::Error),

    //---------------------------------------------------------------------------------------------
    /// A required item is missing, contains the ID of the missing item.
    Missing(String),

    //---------------------------------------------------------------------------------------------
    /// There was an error parsing the TOML file.  Contains the row, column of the error as well
    /// as the actual error message.
    Parse(usize, usize, String),

    //---------------------------------------------------------------------------------------------
    /// There was an error validation an element inside the TOML file.  Contains the ID of the
    /// item that caused the issue as well as the problem.
    Validation(String, ValidationError)
}

impl Display for Error
{
    //*********************************************************************************************
    /// Display a nice message for the warning.
    fn fmt(
        &self,
        fmt : &mut Formatter
        ) -> Result<(), fmt::Error>
    {
        match *self
        {
            Error::FileError(ref err)            => write!(fmt, "File Error: {}", err),
            Error::Missing(ref name)             => write!(fmt, "Required item {} is not defined.", name),
            Error::Parse(row, col, ref error)    => write!(fmt, "Error readingn file at [row {}, column {}] {}", row, col, error),
            Error::Validation(ref item, ref err) => write!(fmt, "Invalid item {}: {}", item, err)
        }
    }
}