mirror of https://github.com/fafhrd91/actix-web
make Responder trait generic over S
This commit is contained in:
parent
8261cf437d
commit
1d01dbaaf9
|
@ -28,11 +28,13 @@
|
|||
|
||||
* Min rustc version is 1.26
|
||||
|
||||
* Use tokio instead of tokio-core
|
||||
|
||||
* `Responder` trait refactored. It is generic over `S`
|
||||
|
||||
* `HttpResponse::into_builder()` now moves cookies into the builder
|
||||
instead of dropping them
|
||||
|
||||
* Use tokio instead of tokio-core
|
||||
|
||||
* Use `&mut self` instead of `&self` for Middleware trait
|
||||
|
||||
* Added header `User-Agent: Actix-web/<current_version>` to default headers when building a request
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
}
|
||||
```
|
||||
|
||||
* `Responder` trait is changed. It is generic over `S` - `Responder<S>`.
|
||||
`Responder::respond_to()` is not generic.
|
||||
|
||||
* [Middleware](https://actix.rs/actix-web/actix_web/middleware/trait.Middleware.html)
|
||||
trait uses `&mut self` instead of `&self`.
|
||||
|
||||
|
|
|
@ -345,7 +345,7 @@ where
|
|||
pub fn route<T, F, R>(mut self, path: &str, method: Method, f: F) -> App<S>
|
||||
where
|
||||
F: Fn(T) -> R + 'static,
|
||||
R: Responder + 'static,
|
||||
R: Responder<S> + 'static,
|
||||
T: FromRequest<S> + 'static,
|
||||
{
|
||||
{
|
||||
|
@ -737,7 +737,7 @@ impl<S: 'static> Iterator for App<S> {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use body::{Body, Binary};
|
||||
use body::{Binary, Body};
|
||||
use http::StatusCode;
|
||||
use httprequest::HttpRequest;
|
||||
use httpresponse::HttpResponse;
|
||||
|
|
|
@ -254,11 +254,11 @@ impl AsRef<[u8]> for Binary {
|
|||
}
|
||||
}
|
||||
|
||||
impl Responder for Binary {
|
||||
impl<S> Responder<S> for Binary {
|
||||
type Item = HttpResponse;
|
||||
type Error = Error;
|
||||
|
||||
fn respond_to<S>(self, req: &HttpRequest<S>) -> Result<HttpResponse, Error> {
|
||||
fn respond_to(self, req: &HttpRequest<S>) -> Result<HttpResponse, Error> {
|
||||
Ok(HttpResponse::build_from(req)
|
||||
.content_type("application/octet-stream")
|
||||
.body(self))
|
||||
|
|
|
@ -743,14 +743,14 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Responder for InternalError<T>
|
||||
impl<T, S> Responder<S> for InternalError<T>
|
||||
where
|
||||
T: Send + Sync + fmt::Debug + fmt::Display + 'static,
|
||||
{
|
||||
type Item = HttpResponse;
|
||||
type Error = Error;
|
||||
|
||||
fn respond_to<S>(self, _: &HttpRequest<S>) -> Result<HttpResponse, Error> {
|
||||
fn respond_to(self, _: &HttpRequest<S>) -> Result<HttpResponse, Error> {
|
||||
Err(self.into())
|
||||
}
|
||||
}
|
||||
|
|
46
src/fs.rs
46
src/fs.rs
|
@ -63,18 +63,20 @@ impl NamedFile {
|
|||
/// let file = NamedFile::open("foo.txt");
|
||||
/// ```
|
||||
pub fn open<P: AsRef<Path>>(path: P) -> io::Result<NamedFile> {
|
||||
use header::{ContentDisposition, DispositionType, DispositionParam};
|
||||
use header::{ContentDisposition, DispositionParam, DispositionType};
|
||||
let path = path.as_ref().to_path_buf();
|
||||
|
||||
// Get the name of the file and use it to construct default Content-Type
|
||||
// and Content-Disposition values
|
||||
let (content_type, content_disposition) =
|
||||
{
|
||||
let (content_type, content_disposition) = {
|
||||
let filename = match path.file_name() {
|
||||
Some(name) => name.to_string_lossy(),
|
||||
None => return Err(io::Error::new(
|
||||
None => {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::InvalidInput,
|
||||
"Provided path has no filename")),
|
||||
"Provided path has no filename",
|
||||
))
|
||||
}
|
||||
};
|
||||
|
||||
let ct = guess_mime_type(&path);
|
||||
|
@ -84,13 +86,11 @@ impl NamedFile {
|
|||
};
|
||||
let cd = ContentDisposition {
|
||||
disposition: disposition_type,
|
||||
parameters: vec![
|
||||
DispositionParam::Filename(
|
||||
parameters: vec![DispositionParam::Filename(
|
||||
header::Charset::Ext("UTF-8".to_owned()),
|
||||
None,
|
||||
filename.as_bytes().to_vec(),
|
||||
)
|
||||
],
|
||||
)],
|
||||
};
|
||||
(ct, cd)
|
||||
};
|
||||
|
@ -268,15 +268,18 @@ fn none_match<S>(etag: Option<&header::EntityTag>, req: &HttpRequest<S>) -> bool
|
|||
}
|
||||
}
|
||||
|
||||
impl Responder for NamedFile {
|
||||
impl<S> Responder<S> for NamedFile {
|
||||
type Item = HttpResponse;
|
||||
type Error = io::Error;
|
||||
|
||||
fn respond_to<S>(self, req: &HttpRequest<S>) -> Result<HttpResponse, io::Error> {
|
||||
fn respond_to(self, req: &HttpRequest<S>) -> Result<HttpResponse, io::Error> {
|
||||
if self.status_code != StatusCode::OK {
|
||||
let mut resp = HttpResponse::build(self.status_code);
|
||||
resp.set(header::ContentType(self.content_type.clone()))
|
||||
.header(header::CONTENT_DISPOSITION, self.content_disposition.to_string());
|
||||
.header(
|
||||
header::CONTENT_DISPOSITION,
|
||||
self.content_disposition.to_string(),
|
||||
);
|
||||
|
||||
if let Some(current_encoding) = self.encoding {
|
||||
resp.content_encoding(current_encoding);
|
||||
|
@ -327,17 +330,18 @@ impl Responder for NamedFile {
|
|||
|
||||
let mut resp = HttpResponse::build(self.status_code);
|
||||
resp.set(header::ContentType(self.content_type.clone()))
|
||||
.header(header::CONTENT_DISPOSITION, self.content_disposition.to_string());
|
||||
.header(
|
||||
header::CONTENT_DISPOSITION,
|
||||
self.content_disposition.to_string(),
|
||||
);
|
||||
|
||||
if let Some(current_encoding) = self.encoding {
|
||||
resp.content_encoding(current_encoding);
|
||||
}
|
||||
|
||||
resp
|
||||
.if_some(last_modified, |lm, resp| {
|
||||
resp.if_some(last_modified, |lm, resp| {
|
||||
resp.set(header::LastModified(lm));
|
||||
})
|
||||
.if_some(etag, |etag, resp| {
|
||||
}).if_some(etag, |etag, resp| {
|
||||
resp.set(header::ETag(etag));
|
||||
});
|
||||
|
||||
|
@ -816,16 +820,14 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_named_file_image_attachment() {
|
||||
use header::{ContentDisposition, DispositionType, DispositionParam};
|
||||
use header::{ContentDisposition, DispositionParam, DispositionType};
|
||||
let cd = ContentDisposition {
|
||||
disposition: DispositionType::Attachment,
|
||||
parameters: vec![
|
||||
DispositionParam::Filename(
|
||||
parameters: vec![DispositionParam::Filename(
|
||||
header::Charset::Ext("UTF-8".to_owned()),
|
||||
None,
|
||||
"test.png".as_bytes().to_vec(),
|
||||
)
|
||||
],
|
||||
)],
|
||||
};
|
||||
let mut file = NamedFile::open("tests/test.png")
|
||||
.unwrap()
|
||||
|
|
|
@ -13,7 +13,7 @@ use httpresponse::HttpResponse;
|
|||
#[allow(unused_variables)]
|
||||
pub trait Handler<S>: 'static {
|
||||
/// The type of value that handler will return.
|
||||
type Result: Responder;
|
||||
type Result: Responder<S>;
|
||||
|
||||
/// Handle request
|
||||
fn handle(&mut self, req: HttpRequest<S>) -> Self::Result;
|
||||
|
@ -22,7 +22,7 @@ pub trait Handler<S>: 'static {
|
|||
/// Trait implemented by types that generate responses for clients.
|
||||
///
|
||||
/// Types that implement this trait can be used as the return type of a handler.
|
||||
pub trait Responder {
|
||||
pub trait Responder<S> {
|
||||
/// The associated item which can be returned.
|
||||
type Item: Into<AsyncResult<HttpResponse>>;
|
||||
|
||||
|
@ -30,9 +30,7 @@ pub trait Responder {
|
|||
type Error: Into<Error>;
|
||||
|
||||
/// Convert itself to `AsyncResult` or `Error`.
|
||||
fn respond_to<S: 'static>(
|
||||
self, req: &HttpRequest<S>,
|
||||
) -> Result<Self::Item, Self::Error>;
|
||||
fn respond_to(self, req: &HttpRequest<S>) -> Result<Self::Item, Self::Error>;
|
||||
}
|
||||
|
||||
/// Trait implemented by types that can be extracted from request.
|
||||
|
@ -93,15 +91,15 @@ pub enum Either<A, B> {
|
|||
B(B),
|
||||
}
|
||||
|
||||
impl<A, B> Responder for Either<A, B>
|
||||
impl<A, B, S> Responder<S> for Either<A, B>
|
||||
where
|
||||
A: Responder,
|
||||
B: Responder,
|
||||
A: Responder<S>,
|
||||
B: Responder<S>,
|
||||
{
|
||||
type Item = AsyncResult<HttpResponse>;
|
||||
type Error = Error;
|
||||
|
||||
fn respond_to<S: 'static>(
|
||||
fn respond_to(
|
||||
self, req: &HttpRequest<S>,
|
||||
) -> Result<AsyncResult<HttpResponse>, Error> {
|
||||
match self {
|
||||
|
@ -133,14 +131,14 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Responder for Option<T>
|
||||
impl<T, S> Responder<S> for Option<T>
|
||||
where
|
||||
T: Responder,
|
||||
T: Responder<S>,
|
||||
{
|
||||
type Item = AsyncResult<HttpResponse>;
|
||||
type Error = Error;
|
||||
|
||||
fn respond_to<S: 'static>(
|
||||
fn respond_to(
|
||||
self, req: &HttpRequest<S>,
|
||||
) -> Result<AsyncResult<HttpResponse>, Error> {
|
||||
match self {
|
||||
|
@ -190,7 +188,7 @@ pub trait AsyncResponder<I, E>: Sized {
|
|||
impl<F, I, E> AsyncResponder<I, E> for F
|
||||
where
|
||||
F: Future<Item = I, Error = E> + 'static,
|
||||
I: Responder + 'static,
|
||||
I: 'static,
|
||||
E: Into<Error> + 'static,
|
||||
{
|
||||
fn responder(self) -> Box<Future<Item = I, Error = E>> {
|
||||
|
@ -202,7 +200,7 @@ where
|
|||
impl<F, R, S> Handler<S> for F
|
||||
where
|
||||
F: Fn(HttpRequest<S>) -> R + 'static,
|
||||
R: Responder + 'static,
|
||||
R: Responder<S> + 'static,
|
||||
{
|
||||
type Result = R;
|
||||
|
||||
|
@ -287,25 +285,21 @@ impl<I, E> AsyncResult<I, E> {
|
|||
}
|
||||
}
|
||||
|
||||
impl Responder for AsyncResult<HttpResponse> {
|
||||
impl<S> Responder<S> for AsyncResult<HttpResponse> {
|
||||
type Item = AsyncResult<HttpResponse>;
|
||||
type Error = Error;
|
||||
|
||||
fn respond_to<S>(
|
||||
self, _: &HttpRequest<S>,
|
||||
) -> Result<AsyncResult<HttpResponse>, Error> {
|
||||
fn respond_to(self, _: &HttpRequest<S>) -> Result<AsyncResult<HttpResponse>, Error> {
|
||||
Ok(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Responder for HttpResponse {
|
||||
impl<S> Responder<S> for HttpResponse {
|
||||
type Item = AsyncResult<HttpResponse>;
|
||||
type Error = Error;
|
||||
|
||||
#[inline]
|
||||
fn respond_to<S>(
|
||||
self, _: &HttpRequest<S>,
|
||||
) -> Result<AsyncResult<HttpResponse>, Error> {
|
||||
fn respond_to(self, _: &HttpRequest<S>) -> Result<AsyncResult<HttpResponse>, Error> {
|
||||
Ok(AsyncResult(Some(AsyncResultItem::Ok(self))))
|
||||
}
|
||||
}
|
||||
|
@ -317,11 +311,11 @@ impl<T> From<T> for AsyncResult<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Responder, E: Into<Error>> Responder for Result<T, E> {
|
||||
type Item = <T as Responder>::Item;
|
||||
impl<S, T: Responder<S>, E: Into<Error>> Responder<S> for Result<T, E> {
|
||||
type Item = <T as Responder<S>>::Item;
|
||||
type Error = Error;
|
||||
|
||||
fn respond_to<S: 'static>(self, req: &HttpRequest<S>) -> Result<Self::Item, Error> {
|
||||
fn respond_to(self, req: &HttpRequest<S>) -> Result<Self::Item, Error> {
|
||||
match self {
|
||||
Ok(val) => match val.respond_to(req) {
|
||||
Ok(val) => Ok(val),
|
||||
|
@ -374,16 +368,16 @@ impl<T> From<Box<Future<Item = T, Error = Error>>> for AsyncResult<T> {
|
|||
/// Convenience type alias
|
||||
pub type FutureResponse<I, E = Error> = Box<Future<Item = I, Error = E>>;
|
||||
|
||||
impl<I, E> Responder for Box<Future<Item = I, Error = E>>
|
||||
impl<S: 'static, I, E> Responder<S> for Box<Future<Item = I, Error = E>>
|
||||
where
|
||||
I: Responder + 'static,
|
||||
I: Responder<S> + 'static,
|
||||
E: Into<Error> + 'static,
|
||||
{
|
||||
type Item = AsyncResult<HttpResponse>;
|
||||
type Error = Error;
|
||||
|
||||
#[inline]
|
||||
fn respond_to<S: 'static>(
|
||||
fn respond_to(
|
||||
self, req: &HttpRequest<S>,
|
||||
) -> Result<AsyncResult<HttpResponse>, Error> {
|
||||
let req = req.clone();
|
||||
|
@ -409,7 +403,7 @@ pub(crate) trait RouteHandler<S>: 'static {
|
|||
pub(crate) struct WrapHandler<S, H, R>
|
||||
where
|
||||
H: Handler<S, Result = R>,
|
||||
R: Responder,
|
||||
R: Responder<S>,
|
||||
S: 'static,
|
||||
{
|
||||
h: H,
|
||||
|
@ -419,7 +413,7 @@ where
|
|||
impl<S, H, R> WrapHandler<S, H, R>
|
||||
where
|
||||
H: Handler<S, Result = R>,
|
||||
R: Responder,
|
||||
R: Responder<S>,
|
||||
S: 'static,
|
||||
{
|
||||
pub fn new(h: H) -> Self {
|
||||
|
@ -430,7 +424,7 @@ where
|
|||
impl<S, H, R> RouteHandler<S> for WrapHandler<S, H, R>
|
||||
where
|
||||
H: Handler<S, Result = R>,
|
||||
R: Responder + 'static,
|
||||
R: Responder<S> + 'static,
|
||||
S: 'static,
|
||||
{
|
||||
fn handle(&mut self, req: HttpRequest<S>) -> AsyncResult<HttpResponse> {
|
||||
|
@ -446,7 +440,7 @@ pub(crate) struct AsyncHandler<S, H, F, R, E>
|
|||
where
|
||||
H: Fn(HttpRequest<S>) -> F + 'static,
|
||||
F: Future<Item = R, Error = E> + 'static,
|
||||
R: Responder + 'static,
|
||||
R: Responder<S> + 'static,
|
||||
E: Into<Error> + 'static,
|
||||
S: 'static,
|
||||
{
|
||||
|
@ -458,7 +452,7 @@ impl<S, H, F, R, E> AsyncHandler<S, H, F, R, E>
|
|||
where
|
||||
H: Fn(HttpRequest<S>) -> F + 'static,
|
||||
F: Future<Item = R, Error = E> + 'static,
|
||||
R: Responder + 'static,
|
||||
R: Responder<S> + 'static,
|
||||
E: Into<Error> + 'static,
|
||||
S: 'static,
|
||||
{
|
||||
|
@ -474,7 +468,7 @@ impl<S, H, F, R, E> RouteHandler<S> for AsyncHandler<S, H, F, R, E>
|
|||
where
|
||||
H: Fn(HttpRequest<S>) -> F + 'static,
|
||||
F: Future<Item = R, Error = E> + 'static,
|
||||
R: Responder + 'static,
|
||||
R: Responder<S> + 'static,
|
||||
E: Into<Error> + 'static,
|
||||
S: 'static,
|
||||
{
|
||||
|
|
|
@ -723,12 +723,12 @@ impl From<HttpResponseBuilder> for HttpResponse {
|
|||
}
|
||||
}
|
||||
|
||||
impl Responder for HttpResponseBuilder {
|
||||
impl<S> Responder<S> for HttpResponseBuilder {
|
||||
type Item = HttpResponse;
|
||||
type Error = Error;
|
||||
|
||||
#[inline]
|
||||
fn respond_to<S>(mut self, _: &HttpRequest<S>) -> Result<HttpResponse, Error> {
|
||||
fn respond_to(mut self, _: &HttpRequest<S>) -> Result<HttpResponse, Error> {
|
||||
Ok(self.finish())
|
||||
}
|
||||
}
|
||||
|
@ -741,11 +741,11 @@ impl From<&'static str> for HttpResponse {
|
|||
}
|
||||
}
|
||||
|
||||
impl Responder for &'static str {
|
||||
impl<S> Responder<S> for &'static str {
|
||||
type Item = HttpResponse;
|
||||
type Error = Error;
|
||||
|
||||
fn respond_to<S>(self, req: &HttpRequest<S>) -> Result<HttpResponse, Error> {
|
||||
fn respond_to(self, req: &HttpRequest<S>) -> Result<HttpResponse, Error> {
|
||||
Ok(req
|
||||
.build_response(StatusCode::OK)
|
||||
.content_type("text/plain; charset=utf-8")
|
||||
|
@ -761,11 +761,11 @@ impl From<&'static [u8]> for HttpResponse {
|
|||
}
|
||||
}
|
||||
|
||||
impl Responder for &'static [u8] {
|
||||
impl<S> Responder<S> for &'static [u8] {
|
||||
type Item = HttpResponse;
|
||||
type Error = Error;
|
||||
|
||||
fn respond_to<S>(self, req: &HttpRequest<S>) -> Result<HttpResponse, Error> {
|
||||
fn respond_to(self, req: &HttpRequest<S>) -> Result<HttpResponse, Error> {
|
||||
Ok(req
|
||||
.build_response(StatusCode::OK)
|
||||
.content_type("application/octet-stream")
|
||||
|
@ -781,11 +781,11 @@ impl From<String> for HttpResponse {
|
|||
}
|
||||
}
|
||||
|
||||
impl Responder for String {
|
||||
impl<S> Responder<S> for String {
|
||||
type Item = HttpResponse;
|
||||
type Error = Error;
|
||||
|
||||
fn respond_to<S>(self, req: &HttpRequest<S>) -> Result<HttpResponse, Error> {
|
||||
fn respond_to(self, req: &HttpRequest<S>) -> Result<HttpResponse, Error> {
|
||||
Ok(req
|
||||
.build_response(StatusCode::OK)
|
||||
.content_type("text/plain; charset=utf-8")
|
||||
|
@ -801,11 +801,11 @@ impl<'a> From<&'a String> for HttpResponse {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Responder for &'a String {
|
||||
impl<'a, S> Responder<S> for &'a String {
|
||||
type Item = HttpResponse;
|
||||
type Error = Error;
|
||||
|
||||
fn respond_to<S>(self, req: &HttpRequest<S>) -> Result<HttpResponse, Error> {
|
||||
fn respond_to(self, req: &HttpRequest<S>) -> Result<HttpResponse, Error> {
|
||||
Ok(req
|
||||
.build_response(StatusCode::OK)
|
||||
.content_type("text/plain; charset=utf-8")
|
||||
|
@ -821,11 +821,11 @@ impl From<Bytes> for HttpResponse {
|
|||
}
|
||||
}
|
||||
|
||||
impl Responder for Bytes {
|
||||
impl<S> Responder<S> for Bytes {
|
||||
type Item = HttpResponse;
|
||||
type Error = Error;
|
||||
|
||||
fn respond_to<S>(self, req: &HttpRequest<S>) -> Result<HttpResponse, Error> {
|
||||
fn respond_to(self, req: &HttpRequest<S>) -> Result<HttpResponse, Error> {
|
||||
Ok(req
|
||||
.build_response(StatusCode::OK)
|
||||
.content_type("application/octet-stream")
|
||||
|
@ -841,11 +841,11 @@ impl From<BytesMut> for HttpResponse {
|
|||
}
|
||||
}
|
||||
|
||||
impl Responder for BytesMut {
|
||||
impl<S> Responder<S> for BytesMut {
|
||||
type Item = HttpResponse;
|
||||
type Error = Error;
|
||||
|
||||
fn respond_to<S>(self, req: &HttpRequest<S>) -> Result<HttpResponse, Error> {
|
||||
fn respond_to(self, req: &HttpRequest<S>) -> Result<HttpResponse, Error> {
|
||||
Ok(req
|
||||
.build_response(StatusCode::OK)
|
||||
.content_type("application/octet-stream")
|
||||
|
|
|
@ -116,11 +116,11 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Serialize> Responder for Json<T> {
|
||||
impl<S, T: Serialize> Responder<S> for Json<T> {
|
||||
type Item = HttpResponse;
|
||||
type Error = Error;
|
||||
|
||||
fn respond_to<S>(self, req: &HttpRequest<S>) -> Result<HttpResponse, Error> {
|
||||
fn respond_to(self, req: &HttpRequest<S>) -> Result<HttpResponse, Error> {
|
||||
let body = serde_json::to_string(&self.0)?;
|
||||
|
||||
Ok(req
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
//! use actix_web::{server, App, Path, Responder};
|
||||
//! # use std::thread;
|
||||
//!
|
||||
//! fn index(info: Path<(String, u32)>) -> impl Responder {
|
||||
//! fn index(info: Path<(String, u32)>) -> impl Responder<()> {
|
||||
//! format!("Hello {}! id:{}", info.0, info.1)
|
||||
//! }
|
||||
//!
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::cell::RefCell;
|
||||
use std::marker::PhantomData;
|
||||
use std::rc::Rc;
|
||||
use std::cell::RefCell;
|
||||
|
||||
use futures::Future;
|
||||
use http::{Method, StatusCode};
|
||||
|
@ -194,7 +194,7 @@ impl<S: 'static> ResourceHandler<S> {
|
|||
pub fn f<F, R>(&mut self, handler: F)
|
||||
where
|
||||
F: Fn(HttpRequest<S>) -> R + 'static,
|
||||
R: Responder + 'static,
|
||||
R: Responder<S> + 'static,
|
||||
{
|
||||
self.routes.push(Route::default());
|
||||
self.routes.last_mut().unwrap().f(handler)
|
||||
|
@ -221,7 +221,7 @@ impl<S: 'static> ResourceHandler<S> {
|
|||
pub fn with<T, F, R>(&mut self, handler: F)
|
||||
where
|
||||
F: Fn(T) -> R + 'static,
|
||||
R: Responder + 'static,
|
||||
R: Responder<S> + 'static,
|
||||
T: FromRequest<S> + 'static,
|
||||
{
|
||||
self.routes.push(Route::default());
|
||||
|
@ -259,7 +259,7 @@ impl<S: 'static> ResourceHandler<S> {
|
|||
where
|
||||
F: Fn(T) -> R + 'static,
|
||||
R: Future<Item = I, Error = E> + 'static,
|
||||
I: Responder + 'static,
|
||||
I: Responder<S> + 'static,
|
||||
E: Into<Error> + 'static,
|
||||
T: FromRequest<S> + 'static,
|
||||
{
|
||||
|
|
10
src/route.rs
10
src/route.rs
|
@ -91,7 +91,7 @@ impl<S: 'static> Route<S> {
|
|||
pub fn f<F, R>(&mut self, handler: F)
|
||||
where
|
||||
F: Fn(HttpRequest<S>) -> R + 'static,
|
||||
R: Responder + 'static,
|
||||
R: Responder<S> + 'static,
|
||||
{
|
||||
self.handler = InnerHandler::new(handler);
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ impl<S: 'static> Route<S> {
|
|||
where
|
||||
H: Fn(HttpRequest<S>) -> F + 'static,
|
||||
F: Future<Item = R, Error = E> + 'static,
|
||||
R: Responder + 'static,
|
||||
R: Responder<S> + 'static,
|
||||
E: Into<Error> + 'static,
|
||||
{
|
||||
self.handler = InnerHandler::async(handler);
|
||||
|
@ -167,7 +167,7 @@ impl<S: 'static> Route<S> {
|
|||
pub fn with<T, F, R>(&mut self, handler: F) -> ExtractorConfig<S, T>
|
||||
where
|
||||
F: Fn(T) -> R + 'static,
|
||||
R: Responder + 'static,
|
||||
R: Responder<S> + 'static,
|
||||
T: FromRequest<S> + 'static,
|
||||
{
|
||||
let cfg = ExtractorConfig::default();
|
||||
|
@ -208,7 +208,7 @@ impl<S: 'static> Route<S> {
|
|||
where
|
||||
F: Fn(T) -> R + 'static,
|
||||
R: Future<Item = I, Error = E> + 'static,
|
||||
I: Responder + 'static,
|
||||
I: Responder<S> + 'static,
|
||||
E: Into<Error> + 'static,
|
||||
T: FromRequest<S> + 'static,
|
||||
{
|
||||
|
@ -233,7 +233,7 @@ impl<S: 'static> InnerHandler<S> {
|
|||
where
|
||||
H: Fn(HttpRequest<S>) -> F + 'static,
|
||||
F: Future<Item = R, Error = E> + 'static,
|
||||
R: Responder + 'static,
|
||||
R: Responder<S> + 'static,
|
||||
E: Into<Error> + 'static,
|
||||
{
|
||||
InnerHandler(Rc::new(UnsafeCell::new(Box::new(AsyncHandler::new(h)))))
|
||||
|
|
|
@ -222,7 +222,7 @@ impl<S: 'static> Scope<S> {
|
|||
pub fn route<T, F, R>(mut self, path: &str, method: Method, f: F) -> Scope<S>
|
||||
where
|
||||
F: Fn(T) -> R + 'static,
|
||||
R: Responder + 'static,
|
||||
R: Responder<S> + 'static,
|
||||
T: FromRequest<S> + 'static,
|
||||
{
|
||||
// get resource handler
|
||||
|
|
|
@ -589,7 +589,7 @@ impl<S: 'static> TestRequest<S> {
|
|||
where
|
||||
H: Fn(HttpRequest<S>) -> F + 'static,
|
||||
F: Future<Item = R, Error = E> + 'static,
|
||||
R: Responder<Error = E> + 'static,
|
||||
R: Responder<S, Error = E> + 'static,
|
||||
E: Into<Error> + 'static,
|
||||
{
|
||||
let req = self.finish();
|
||||
|
|
16
src/with.rs
16
src/with.rs
|
@ -134,7 +134,7 @@ where
|
|||
impl<T, S, F, R> Handler<S> for With<T, S, F, R>
|
||||
where
|
||||
F: Fn(T) -> R + 'static,
|
||||
R: Responder + 'static,
|
||||
R: Responder<S> + 'static,
|
||||
T: FromRequest<S> + 'static,
|
||||
S: 'static,
|
||||
{
|
||||
|
@ -161,7 +161,7 @@ where
|
|||
struct WithHandlerFut<T, S, F, R>
|
||||
where
|
||||
F: Fn(T) -> R,
|
||||
R: Responder,
|
||||
R: Responder<S>,
|
||||
T: FromRequest<S> + 'static,
|
||||
S: 'static,
|
||||
{
|
||||
|
@ -176,7 +176,7 @@ where
|
|||
impl<T, S, F, R> Future for WithHandlerFut<T, S, F, R>
|
||||
where
|
||||
F: Fn(T) -> R,
|
||||
R: Responder + 'static,
|
||||
R: Responder<S> + 'static,
|
||||
T: FromRequest<S> + 'static,
|
||||
S: 'static,
|
||||
{
|
||||
|
@ -227,7 +227,7 @@ pub struct WithAsync<T, S, F, R, I, E>
|
|||
where
|
||||
F: Fn(T) -> R,
|
||||
R: Future<Item = I, Error = E>,
|
||||
I: Responder,
|
||||
I: Responder<S>,
|
||||
E: Into<E>,
|
||||
T: FromRequest<S>,
|
||||
S: 'static,
|
||||
|
@ -241,7 +241,7 @@ impl<T, S, F, R, I, E> WithAsync<T, S, F, R, I, E>
|
|||
where
|
||||
F: Fn(T) -> R,
|
||||
R: Future<Item = I, Error = E>,
|
||||
I: Responder,
|
||||
I: Responder<S>,
|
||||
E: Into<Error>,
|
||||
T: FromRequest<S>,
|
||||
S: 'static,
|
||||
|
@ -259,7 +259,7 @@ impl<T, S, F, R, I, E> Handler<S> for WithAsync<T, S, F, R, I, E>
|
|||
where
|
||||
F: Fn(T) -> R + 'static,
|
||||
R: Future<Item = I, Error = E> + 'static,
|
||||
I: Responder + 'static,
|
||||
I: Responder<S> + 'static,
|
||||
E: Into<Error> + 'static,
|
||||
T: FromRequest<S> + 'static,
|
||||
S: 'static,
|
||||
|
@ -289,7 +289,7 @@ struct WithAsyncHandlerFut<T, S, F, R, I, E>
|
|||
where
|
||||
F: Fn(T) -> R,
|
||||
R: Future<Item = I, Error = E> + 'static,
|
||||
I: Responder + 'static,
|
||||
I: Responder<S> + 'static,
|
||||
E: Into<Error> + 'static,
|
||||
T: FromRequest<S> + 'static,
|
||||
S: 'static,
|
||||
|
@ -307,7 +307,7 @@ impl<T, S, F, R, I, E> Future for WithAsyncHandlerFut<T, S, F, R, I, E>
|
|||
where
|
||||
F: Fn(T) -> R,
|
||||
R: Future<Item = I, Error = E> + 'static,
|
||||
I: Responder + 'static,
|
||||
I: Responder<S> + 'static,
|
||||
E: Into<Error> + 'static,
|
||||
T: FromRequest<S> + 'static,
|
||||
S: 'static,
|
||||
|
|
Loading…
Reference in New Issue