Remove unnecessary second 'Handler' lifetimes.

This commit is contained in:
Sergio Benitez 2021-04-13 21:54:28 -07:00
parent c49585bb39
commit fe4d0425e6
4 changed files with 14 additions and 18 deletions

View File

@ -356,7 +356,7 @@ impl Into<Vec<Route>> for StaticFiles {
#[rocket::async_trait] #[rocket::async_trait]
impl Handler for StaticFiles { impl Handler for StaticFiles {
async fn handle<'r, 's: 'r>(&'s self, req: &'r Request<'_>, data: Data) -> Outcome<'r> { async fn handle<'r>(&self, req: &'r Request<'_>, data: Data) -> Outcome<'r> {
// Get the segments as a `PathBuf`, allowing dotfiles requested. // Get the segments as a `PathBuf`, allowing dotfiles requested.
let options = self.options; let options = self.options;
let allow_dotfiles = options.contains(Options::DotFiles); let allow_dotfiles = options.contains(Options::DotFiles);

View File

@ -45,11 +45,7 @@ pub type BoxFuture<'r, T = Result<'r>> = futures::future::BoxFuture<'r, T>;
/// ///
/// #[rocket::async_trait] /// #[rocket::async_trait]
/// impl catcher::Handler for CustomHandler { /// impl catcher::Handler for CustomHandler {
/// async fn handle<'r, 's: 'r>( /// async fn handle<'r>(&self, status: Status, req: &'r Request<'_>) -> catcher::Result<'r> {
/// &'s self,
/// status: Status,
/// req: &'r Request<'_>
/// ) -> catcher::Result<'r> {
/// let inner = match self.0 { /// let inner = match self.0 {
/// Kind::Simple => "simple".respond_to(req)?, /// Kind::Simple => "simple".respond_to(req)?,
/// Kind::Intermediate => "intermediate".respond_to(req)?, /// Kind::Intermediate => "intermediate".respond_to(req)?,
@ -101,21 +97,21 @@ pub trait Handler: Cloneable + Send + Sync + 'static {
/// Nevertheless, failure is allowed, both for convenience and necessity. If /// Nevertheless, failure is allowed, both for convenience and necessity. If
/// an error handler fails, Rocket's default `500` catcher is invoked. If it /// an error handler fails, Rocket's default `500` catcher is invoked. If it
/// succeeds, the returned `Response` is used to respond to the client. /// succeeds, the returned `Response` is used to respond to the client.
async fn handle<'r, 's: 'r>(&'s self, status: Status, req: &'r Request<'_>) -> Result<'r>; async fn handle<'r>(&self, status: Status, req: &'r Request<'_>) -> Result<'r>;
} }
// We write this manually to avoid double-boxing. // We write this manually to avoid double-boxing.
impl<F: Clone + Sync + Send + 'static> Handler for F impl<F: Clone + Sync + Send + 'static> Handler for F
where for<'x> F: Fn(Status, &'x Request<'_>) -> BoxFuture<'x>, where for<'x> F: Fn(Status, &'x Request<'_>) -> BoxFuture<'x>,
{ {
fn handle<'r, 's: 'r, 'life0, 'async_trait>( fn handle<'r, 'life0, 'life1, 'async_trait>(
&'s self, &'life0 self,
status: Status, status: Status,
req: &'r Request<'life0>, req: &'r Request<'life1>,
) -> BoxFuture<'r> ) -> BoxFuture<'r>
where 'r: 'async_trait, where 'r: 'async_trait,
's: 'async_trait,
'life0: 'async_trait, 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait, Self: 'async_trait,
{ {
self(status, req) self(status, req)

View File

@ -53,7 +53,7 @@ pub type BoxFuture<'r, T = Outcome<'r>> = futures::future::BoxFuture<'r, T>;
/// ///
/// #[rocket::async_trait] /// #[rocket::async_trait]
/// impl Handler for CustomHandler { /// impl Handler for CustomHandler {
/// async fn handle<'r, 's: 'r>(&'s self, req: &'r Request<'_>, data: Data) -> Outcome<'r> { /// async fn handle<'r>(&self, req: &'r Request<'_>, data: Data) -> Outcome<'r> {
/// match self.0 { /// match self.0 {
/// Kind::Simple => Outcome::from(req, "simple"), /// Kind::Simple => Outcome::from(req, "simple"),
/// Kind::Intermediate => Outcome::from(req, "intermediate"), /// Kind::Intermediate => Outcome::from(req, "intermediate"),
@ -145,7 +145,7 @@ pub trait Handler: Cloneable + Send + Sync + 'static {
/// generate a response. Otherwise, if the return value is `Forward(Data)`, /// generate a response. Otherwise, if the return value is `Forward(Data)`,
/// the next matching route is attempted. If there are no other matching /// the next matching route is attempted. If there are no other matching
/// routes, the `404` error catcher is invoked. /// routes, the `404` error catcher is invoked.
async fn handle<'r, 's: 'r>(&'s self, request: &'r Request<'_>, data: Data) -> Outcome<'r>; async fn handle<'r>(&self, request: &'r Request<'_>, data: Data) -> Outcome<'r>;
} }
// We write this manually to avoid double-boxing. // We write this manually to avoid double-boxing.
@ -153,14 +153,14 @@ impl<F: Clone + Sync + Send + 'static> Handler for F
where for<'x> F: Fn(&'x Request<'_>, Data) -> BoxFuture<'x>, where for<'x> F: Fn(&'x Request<'_>, Data) -> BoxFuture<'x>,
{ {
#[inline(always)] #[inline(always)]
fn handle<'r, 's: 'r, 'life0, 'async_trait>( fn handle<'r, 'life0, 'life1, 'async_trait>(
&'s self, &'life0 self,
req: &'r Request<'life0>, req: &'r Request<'life1>,
data: Data, data: Data,
) -> BoxFuture<'r> ) -> BoxFuture<'r>
where 'r: 'async_trait, where 'r: 'async_trait,
's: 'async_trait,
'life0: 'async_trait, 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait, Self: 'async_trait,
{ {
self(req, data) self(req, data)

View File

@ -80,7 +80,7 @@ impl CustomHandler {
#[rocket::async_trait] #[rocket::async_trait]
impl route::Handler for CustomHandler { impl route::Handler for CustomHandler {
async fn handle<'r, 's: 'r>(&'s self, req: &'r Request<'_>, data: Data) -> route::Outcome<'r> { async fn handle<'r>(&self, req: &'r Request<'_>, data: Data) -> route::Outcome<'r> {
let self_data = self.data; let self_data = self.data;
let id = req.param::<&str>(0) let id = req.param::<&str>(0)
.and_then(|res| res.ok()) .and_then(|res| res.ok())