reep 0.2.0

[deprecated] REsource EndPoint (REEP): Generic Iron Endpoint for RESTlike Resource Access
Documentation
use iron::typemap::Key;
use iron::{IronResult, Request};
use std::any::Any;


/// Interface for OptionParser and BodyParser entforcing type corektness and results
pub trait ParserMiddleware: Key + Sync + Send + Any  {
    /// called befor handing a endpoint with a Body/Options
    /// not that the id in the url is expected to be percent_encoded and will be
    /// decoded to utf-8 before being passed to parse. Illegal UTF-8 encodings
    /// will be replaced with  U+FFFD (see url::percent_encoding::lossy_utf8_percent_decode)
    /// NOTE: in future version lossy decoding might be replaced with a more strict decoding
    /// Never relay on the fact thats lossy decoded
    fn parse(&self, req: &mut Request) -> IronResult<Self::Value>;
}

/// A Type witch can be constructed from a &str but witch construction might fail
pub trait ParsableId: Sized {
    ///create a id using the passed URL id part string
    ///if the result errs it is like if a BeforeMiddleware returned a error
    fn parse(from: &str) -> IronResult<Self>;
}

/// The trait for a Id
pub trait Id: ParsableId + Into<String> + Clone + Key<Value=Self> {}


/// The trait representing resources
pub trait Resource: Any{
    /// The Id Type used to identitfy this resource
    type RId: Id + Any;

    /// Return a referenc to the Id of this Resource,
    /// if it has one.
    fn id_ref(&self) -> Option<&Self::RId>;
}

/// Trait for the OptionParser, also used As Key for the Parsers Result
/// on the requests extensuon typemap
pub trait OptionParser: ParserMiddleware {}

/// Trait for the BodyParser, also used As Key for the Parsers Result
/// on the requests extensuon typemap
pub trait BodyParser<T: Resource+Any>: Key<Value=T> + ParserMiddleware {}