1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#![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 {}