mirror of https://github.com/rwf2/Rocket.git
Remove unnecessary boxing of some Futures.
This commit is contained in:
parent
1f90a9b6d1
commit
bd929ef617
|
@ -155,11 +155,9 @@ macro_rules! default_catchers {
|
|||
|
||||
$(
|
||||
fn $fn_name<'r>(req: &'r Request<'_>) -> std::pin::Pin<Box<dyn std::future::Future<Output = response::Result<'r>> + Send + 'r>> {
|
||||
(async move {
|
||||
status::Custom(Status::from_code($code).unwrap(),
|
||||
content::Html(error_page_template!($code, $name, $description))
|
||||
).respond_to(req).await
|
||||
}).boxed()
|
||||
status::Custom(Status::from_code($code).unwrap(),
|
||||
content::Html(error_page_template!($code, $name, $description))
|
||||
).respond_to(req)
|
||||
}
|
||||
|
||||
map.insert($code, Catcher::new_default($code, $fn_name));
|
||||
|
@ -171,7 +169,6 @@ macro_rules! default_catchers {
|
|||
|
||||
pub mod defaults {
|
||||
use super::Catcher;
|
||||
use futures::future::FutureExt;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ use std::fs::File;
|
|||
use std::io::Cursor;
|
||||
|
||||
use futures::io::BufReader;
|
||||
use futures::future;
|
||||
|
||||
use crate::http::{Status, ContentType, StatusClass};
|
||||
use crate::response::{self, Response, Body};
|
||||
|
@ -278,15 +279,13 @@ impl Responder<'_> for () {
|
|||
/// a warning message and returns an `Err` of `Status::NotFound`.
|
||||
impl<'r, R: Responder<'r> + Send + 'r> Responder<'r> for Option<R> {
|
||||
fn respond_to(self, req: &'r Request<'_>) -> response::ResultFuture<'r> {
|
||||
Box::pin(async move {
|
||||
match self {
|
||||
Some(r) => r.respond_to(req).await,
|
||||
None => {
|
||||
warn_!("Response was `None`.");
|
||||
Err(Status::NotFound)
|
||||
},
|
||||
}
|
||||
})
|
||||
match self {
|
||||
Some(r) => r.respond_to(req),
|
||||
None => {
|
||||
warn_!("Response was `None`.");
|
||||
Box::pin(future::err(Status::NotFound))
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -294,12 +293,10 @@ impl<'r, R: Responder<'r> + Send + 'r> Responder<'r> for Option<R> {
|
|||
/// `Err`.
|
||||
impl<'r, R: Responder<'r> + Send + 'r, E: Responder<'r> + Send + 'r> Responder<'r> for Result<R, E> {
|
||||
fn respond_to(self, req: &'r Request<'_>) -> response::ResultFuture<'r> {
|
||||
Box::pin(async move {
|
||||
match self {
|
||||
Ok(responder) => responder.respond_to(req).await,
|
||||
Err(responder) => responder.respond_to(req).await,
|
||||
}
|
||||
})
|
||||
match self {
|
||||
Ok(responder) => responder.respond_to(req),
|
||||
Err(responder) => responder.respond_to(req),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue