From f3beb68491d1fb2ab506271fdd6e3238f0bb7162 Mon Sep 17 00:00:00 2001 From: Jonathan Dickinson Date: Thu, 23 Jul 2020 13:08:49 -0700 Subject: [PATCH] Remove superfluous lifetimes in 'Fairing' methods. --- contrib/lib/src/compression/fairing.rs | 2 +- contrib/lib/src/helmet/helmet.rs | 2 +- contrib/lib/src/templates/fairing.rs | 2 +- core/lib/src/fairing/ad_hoc.rs | 4 ++-- core/lib/src/fairing/fairings.rs | 2 +- core/lib/src/fairing/mod.rs | 20 ++++++++++---------- examples/fairings/src/main.rs | 4 ++-- site/guide/7-fairings.md | 4 ++-- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/contrib/lib/src/compression/fairing.rs b/contrib/lib/src/compression/fairing.rs index 8de4cee7..00f98975 100644 --- a/contrib/lib/src/compression/fairing.rs +++ b/contrib/lib/src/compression/fairing.rs @@ -144,7 +144,7 @@ impl Fairing for Compression { Ok(rocket.manage(ctxt)) } - fn on_response(&self, request: &Request<'_>, response: &mut Response<'_>) { + fn on_response<'r>(&self, request: &'r Request<'_>, response: &mut Response<'r>) { let context = request .guard::>() .expect("Compression Context registered in on_attach"); diff --git a/contrib/lib/src/helmet/helmet.rs b/contrib/lib/src/helmet/helmet.rs index 8ca38316..6eb2837d 100644 --- a/contrib/lib/src/helmet/helmet.rs +++ b/contrib/lib/src/helmet/helmet.rs @@ -197,7 +197,7 @@ impl Fairing for SpaceHelmet { } } - async fn on_response<'a>(&'a self, _: &'a Request<'_>, res: &'a mut Response<'_>) { + async fn on_response<'r>(&self, _: &'r Request<'_>, res: &mut Response<'r>) { self.apply(res); } diff --git a/contrib/lib/src/templates/fairing.rs b/contrib/lib/src/templates/fairing.rs index 07f55372..17a98cc1 100644 --- a/contrib/lib/src/templates/fairing.rs +++ b/contrib/lib/src/templates/fairing.rs @@ -173,7 +173,7 @@ impl Fairing for TemplateFairing { } #[cfg(debug_assertions)] - async fn on_request<'a>(&'a self, req: &'a mut rocket::Request<'_>, _data: &'a rocket::Data) { + async fn on_request(&self, req: &mut rocket::Request<'_>, _data: &rocket::Data) { let cm = req.guard::>().await .expect("Template ContextManager registered in on_attach"); diff --git a/core/lib/src/fairing/ad_hoc.rs b/core/lib/src/fairing/ad_hoc.rs index 9902c3c6..7ffbaf2d 100644 --- a/core/lib/src/fairing/ad_hoc.rs +++ b/core/lib/src/fairing/ad_hoc.rs @@ -212,13 +212,13 @@ impl Fairing for AdHoc { } } - async fn on_request<'a>(&'a self, req: &'a mut Request<'_>, data: &'a Data) { + async fn on_request(&self, req: &mut Request<'_>, data: &Data) { if let AdHocKind::Request(ref callback) = self.kind { callback(req, data).await; } } - async fn on_response<'a>(&'a self, req: &'a Request<'_>, res: &'a mut Response<'_>) { + async fn on_response<'r>(&self, req: &'r Request<'_>, res: &mut Response<'r>) { if let AdHocKind::Response(ref callback) = self.kind { callback(req, res).await; } diff --git a/core/lib/src/fairing/fairings.rs b/core/lib/src/fairing/fairings.rs index b09ac965..0e492bb8 100644 --- a/core/lib/src/fairing/fairings.rs +++ b/core/lib/src/fairing/fairings.rs @@ -66,7 +66,7 @@ impl Fairings { } #[inline(always)] - pub async fn handle_response<'r>(&self, request: &Request<'r>, response: &mut Response<'r>) { + pub async fn handle_response<'r>(&self, request: &'r Request<'_>, response: &mut Response<'r>) { for &i in &self.response { self.all_fairings[i].on_response(request, response).await; } diff --git a/core/lib/src/fairing/mod.rs b/core/lib/src/fairing/mod.rs index 5abd814b..7a3a335e 100644 --- a/core/lib/src/fairing/mod.rs +++ b/core/lib/src/fairing/mod.rs @@ -217,12 +217,12 @@ pub use self::info_kind::{Info, Kind}; /// # unimplemented!() /// } /// -/// async fn on_request<'a>(&'a self, req: &'a mut Request<'_>, data: &'a Data) { +/// async fn on_request(&self, req: &mut Request<'_>, data: &Data) { /// /* ... */ /// # unimplemented!() /// } /// -/// async fn on_response<'a>(&'a self, req: &'a Request<'_>, res: &'a mut Response<'_>) { +/// async fn on_response<'r>(&self, req: &'r Request<'_>, res: &mut Response<'r>) { /// /* ... */ /// # unimplemented!() /// } @@ -266,7 +266,7 @@ pub use self::info_kind::{Info, Kind}; /// } /// } /// -/// async fn on_request<'a>(&'a self, req: &'a mut Request<'_>, _: &'a Data) { +/// async fn on_request(&self, req: &mut Request<'_>, _: &Data) { /// if req.method() == Method::Get { /// self.get.fetch_add(1, Ordering::Relaxed); /// } else if req.method() == Method::Post { @@ -274,7 +274,7 @@ pub use self::info_kind::{Info, Kind}; /// } /// } /// -/// async fn on_response<'a>(&'a self, req: &'a Request<'_>, res: &'a mut Response<'_>) { +/// async fn on_response<'r>(&self, req: &'r Request<'_>, res: &mut Response<'r>) { /// // Don't change a successful user's response, ever. /// if res.status() != Status::NotFound { /// return @@ -329,7 +329,7 @@ pub use self::info_kind::{Info, Kind}; /// } /// /// /// Stores the start time of the request in request-local state. -/// async fn on_request<'a>(&'a self, request: &'a mut Request<'_>, _: &'a Data) { +/// async fn on_request(&self, request: &mut Request<'_>, _: &Data) { /// // Store a `TimerStart` instead of directly storing a `SystemTime` /// // to ensure that this usage doesn't conflict with anything else /// // that might store a `SystemTime` in request-local cache. @@ -338,7 +338,7 @@ pub use self::info_kind::{Info, Kind}; /// /// /// Adds a header to the response indicating how long the server took to /// /// process the request. -/// async fn on_response<'a>(&'a self, req: &'a Request<'_>, res: &'a mut Response<'_>) { +/// async fn on_response<'r>(&self, req: &'r Request<'_>, res: &mut Response<'r>) { /// let start_time = req.local_cache(|| TimerStart(None)); /// if let Some(Ok(duration)) = start_time.0.map(|st| st.elapsed()) { /// let ms = duration.as_secs() * 1000 + duration.subsec_millis() as u64; @@ -440,7 +440,7 @@ pub trait Fairing: Send + Sync + 'static { /// /// The default implementation of this method does nothing. #[allow(unused_variables)] - async fn on_request<'a>(&'a self, req: &'a mut Request<'_>, data: &'a Data) {} + async fn on_request(&self, req: &mut Request<'_>, data: &Data) {} /// The response callback. /// @@ -453,7 +453,7 @@ pub trait Fairing: Send + Sync + 'static { /// /// The default implementation of this method does nothing. #[allow(unused_variables)] - async fn on_response<'a>(&'a self, req: &'a Request<'_>, res: &'a mut Response<'_>) {} + async fn on_response<'r>(&self, req: &'r Request<'_>, res: &mut Response<'r>) {} } #[crate::async_trait] @@ -474,12 +474,12 @@ impl Fairing for std::sync::Arc { } #[inline] - async fn on_request<'a>(&'a self, req: &'a mut Request<'_>, data: &'a Data) { + async fn on_request(&self, req: &mut Request<'_>, data: &Data) { (self as &T).on_request(req, data).await; } #[inline] - async fn on_response<'a>(&'a self, req: &'a Request<'_>, res: &'a mut Response<'_>) { + async fn on_response<'r>(&self, req: &'r Request<'_>, res: &mut Response<'r>) { (self as &T).on_response(req, res).await; } } diff --git a/examples/fairings/src/main.rs b/examples/fairings/src/main.rs index 8b96a9a3..fe491347 100644 --- a/examples/fairings/src/main.rs +++ b/examples/fairings/src/main.rs @@ -26,7 +26,7 @@ impl Fairing for Counter { } } - async fn on_request<'a>(&'a self, request: &'a mut Request<'_>, _: &'a Data) { + async fn on_request(&self, request: &mut Request<'_>, _: &Data) { if request.method() == Method::Get { self.get.fetch_add(1, Ordering::Relaxed); } else if request.method() == Method::Post { @@ -34,7 +34,7 @@ impl Fairing for Counter { } } - async fn on_response<'a>(&'a self, req: &'a Request<'_>, res: &'a mut Response<'_>) { + async fn on_response<'r>(&self, req: &'r Request<'_>, res: &mut Response<'r>) { if res.status() != Status::NotFound { return } diff --git a/site/guide/7-fairings.md b/site/guide/7-fairings.md index a23c4eef..57f9d707 100644 --- a/site/guide/7-fairings.md +++ b/site/guide/7-fairings.md @@ -169,7 +169,7 @@ impl Fairing for Counter { } // Increment the counter for `GET` and `POST` requests. - async fn on_request<'a>(&'a self, request: &'a mut Request<'_>, _: &'a Data) { + async fn on_request(&self, request: &mut Request<'_>, _: &Data) { match request.method() { Method::Get => self.get.fetch_add(1, Ordering::Relaxed), Method::Post => self.post.fetch_add(1, Ordering::Relaxed), @@ -177,7 +177,7 @@ impl Fairing for Counter { }; } - async fn on_response<'a>(&'a self, request: &'a Request<'_>, response: &'a mut Response<'_>) { + async fn on_response<'r>(&self, request: &'r Request<'_>, response: &mut Response<'r>) { // Don't change a successful user's response, ever. if response.status() != Status::NotFound { return