reep-id-string 0.2.0

[deprecated] plain string impl. of reep::types::Id with optional serialisation support
Documentation
#![deny(missing_docs)]

//! A "just a string' implementation for reep::types::Id
//! it supports serialisation with rustc-serialize and serde.
//! Use the rustc-serialize-support/serde-support feature to enable
//! the respective serialisation framework support

extern crate iron;
extern crate reep;

#[cfg(feature = "rustc-serialize-support")]
extern crate rustc_serialize;
#[cfg(feature = "serde-support")]
extern crate serde;

use iron::typemap::Key;
use iron::IronResult;
use reep::types::{ParsableId, Id};

//replublish all needed optional  methodes/types
#[cfg(feature = "rustc-serialize-support")]
pub use rustc_serialize_support::*;
#[cfg(feature = "serde-support")]
pub use serde_support::*;

//inklude optional modules if needed
#[cfg(feature = "rustc-serialize-support")]
mod rustc_serialize_support;
#[cfg(feature = "serde-support")]
mod serde_support;

/// a default plain string id implementation
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct DefaultId(String);

impl DefaultId {
    /// create a new DefaultId wraping given string
    pub fn new(s: String) -> DefaultId {
        DefaultId(s)
    }
}

impl Into<String> for DefaultId {
    fn into(self) -> String {
        self.0
    }
}

impl ParsableId for DefaultId {
    fn parse(s: &str) -> IronResult<DefaultId> {
        Ok(DefaultId(s.into()))
    }
}

impl Key for DefaultId {
    type Value = Self;
}

impl Id for DefaultId {}