reep_id_string/
lib.rs

1#![deny(missing_docs)]
2
3//! A "just a string' implementation for reep::types::Id
4//! it supports serialisation with rustc-serialize and serde.
5//! Use the rustc-serialize-support/serde-support feature to enable
6//! the respective serialisation framework support
7
8extern crate iron;
9extern crate reep;
10
11#[cfg(feature = "rustc-serialize-support")]
12extern crate rustc_serialize;
13#[cfg(feature = "serde-support")]
14extern crate serde;
15
16use iron::typemap::Key;
17use iron::IronResult;
18use reep::types::{ParsableId, Id};
19
20//replublish all needed optional  methodes/types
21#[cfg(feature = "rustc-serialize-support")]
22pub use rustc_serialize_support::*;
23#[cfg(feature = "serde-support")]
24pub use serde_support::*;
25
26//inklude optional modules if needed
27#[cfg(feature = "rustc-serialize-support")]
28mod rustc_serialize_support;
29#[cfg(feature = "serde-support")]
30mod serde_support;
31
32/// a default plain string id implementation
33#[derive(Clone, Debug, PartialEq, Eq, Hash)]
34pub struct DefaultId(String);
35
36impl DefaultId {
37    /// create a new DefaultId wraping given string
38    pub fn new(s: String) -> DefaultId {
39        DefaultId(s)
40    }
41}
42
43impl Into<String> for DefaultId {
44    fn into(self) -> String {
45        self.0
46    }
47}
48
49impl ParsableId for DefaultId {
50    fn parse(s: &str) -> IronResult<DefaultId> {
51        Ok(DefaultId(s.into()))
52    }
53}
54
55impl Key for DefaultId {
56    type Value = Self;
57}
58
59impl Id for DefaultId {}