use error;
use response::{Context, Serializer};
use util::BufStream;
use bytes::Buf;
use http;
pub trait Response {
type Buf: Buf;
type Body: BufStream<Item = Self::Buf, Error = ::Error>;
fn into_http<S: Serializer>(self, context: &Context<S>) -> Result<http::Response<Self::Body>, ::Error>;
}
impl<T> Response for http::Response<T>
where T: BufStream,
{
type Buf = T::Item;
type Body = error::Map<T>;
fn into_http<S: Serializer>(self, _: &Context<S>) -> Result<http::Response<Self::Body>, ::Error> {
Ok(self.map(error::Map::new))
}
}
impl<R, E> Response for Result<R, E>
where R: Response,
E: Into<::Error>,
{
type Buf = R::Buf;
type Body = R::Body;
fn into_http<S: Serializer>(self, context: &Context<S>) -> Result<http::Response<Self::Body>, ::Error> {
self.map_err(|err| err.into()).and_then(|resp| resp.into_http(context))
}
}