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 shareable::SharedObject;

use item_value::ItemValue;
use notify::Notify;

//*************************************************************************************************
/// This object will provide the value of an item read from the TOML file.  It's value is
/// initialized to "" until the TOML file is actually loaded.
#[derive(Clone)]
pub struct StringValue
{
    //---------------------------------------------------------------------------------------------
    /// The data object that actually holds the value.
    value : SharedObject<String>
}

impl StringValue
{
    //---------------------------------------------------------------------------------------------
    /// Create a new instance of the object.
    pub fn new() -> StringValue
    {
        StringValue {
            value  : SharedObject::new(String::from(""))
        }
    }

    //---------------------------------------------------------------------------------------------
    /// Returns a clone of the string read from the TOML file.
    pub fn get(&self) -> String
    {
        String::from(self.value.get().as_str())
    }
}

use std::fmt::{Debug, Display, Formatter, Error};

impl Debug for StringValue
{
    //*********************************************************************************************
    /// Implementation of Debug.
    fn fmt(
        &self,
        f : &mut Formatter
        ) -> Result<(), Error>
    {
        write!(f, "{:?}", self.get())
    }
}

impl Display for StringValue
{
    //*********************************************************************************************
    /// Implementation of Display.
    fn fmt(
        &self,
        f : &mut Formatter
        ) -> Result<(), Error>
    {
        write!(f, "{}", self.get())
    }
}

impl Notify for StringValue
{
    //---------------------------------------------------------------------------------------------
    /// This is called when the TOML file is read to set the value.
    fn send(
        &self,
        value : &ItemValue
        )
    {
        self.value.set(String::from(value.get_str()));
    }
}