mirror of https://github.com/rwf2/Rocket.git
Remove superfluous lifetimes in 'Fairing' methods.
This commit is contained in:
parent
0ff4b0d5ad
commit
f3beb68491
|
@ -144,7 +144,7 @@ impl Fairing for Compression {
|
||||||
Ok(rocket.manage(ctxt))
|
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
|
let context = request
|
||||||
.guard::<rocket::State<'_, Context>>()
|
.guard::<rocket::State<'_, Context>>()
|
||||||
.expect("Compression Context registered in on_attach");
|
.expect("Compression Context registered in on_attach");
|
||||||
|
|
|
@ -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);
|
self.apply(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -173,7 +173,7 @@ impl Fairing for TemplateFairing {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[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::<rocket::State<'_, ContextManager>>().await
|
let cm = req.guard::<rocket::State<'_, ContextManager>>().await
|
||||||
.expect("Template ContextManager registered in on_attach");
|
.expect("Template ContextManager registered in on_attach");
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
if let AdHocKind::Request(ref callback) = self.kind {
|
||||||
callback(req, data).await;
|
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 {
|
if let AdHocKind::Response(ref callback) = self.kind {
|
||||||
callback(req, res).await;
|
callback(req, res).await;
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ impl Fairings {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[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 {
|
for &i in &self.response {
|
||||||
self.all_fairings[i].on_response(request, response).await;
|
self.all_fairings[i].on_response(request, response).await;
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,12 +217,12 @@ pub use self::info_kind::{Info, Kind};
|
||||||
/// # unimplemented!()
|
/// # 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!()
|
/// # 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!()
|
/// # 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 {
|
/// if req.method() == Method::Get {
|
||||||
/// self.get.fetch_add(1, Ordering::Relaxed);
|
/// self.get.fetch_add(1, Ordering::Relaxed);
|
||||||
/// } else if req.method() == Method::Post {
|
/// } 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.
|
/// // Don't change a successful user's response, ever.
|
||||||
/// if res.status() != Status::NotFound {
|
/// if res.status() != Status::NotFound {
|
||||||
/// return
|
/// return
|
||||||
|
@ -329,7 +329,7 @@ pub use self::info_kind::{Info, Kind};
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// /// Stores the start time of the request in request-local state.
|
/// /// 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`
|
/// // Store a `TimerStart` instead of directly storing a `SystemTime`
|
||||||
/// // to ensure that this usage doesn't conflict with anything else
|
/// // to ensure that this usage doesn't conflict with anything else
|
||||||
/// // that might store a `SystemTime` in request-local cache.
|
/// // 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
|
/// /// Adds a header to the response indicating how long the server took to
|
||||||
/// /// process the request.
|
/// /// 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));
|
/// let start_time = req.local_cache(|| TimerStart(None));
|
||||||
/// if let Some(Ok(duration)) = start_time.0.map(|st| st.elapsed()) {
|
/// if let Some(Ok(duration)) = start_time.0.map(|st| st.elapsed()) {
|
||||||
/// let ms = duration.as_secs() * 1000 + duration.subsec_millis() as u64;
|
/// 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.
|
/// The default implementation of this method does nothing.
|
||||||
#[allow(unused_variables)]
|
#[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.
|
/// The response callback.
|
||||||
///
|
///
|
||||||
|
@ -453,7 +453,7 @@ pub trait Fairing: Send + Sync + 'static {
|
||||||
///
|
///
|
||||||
/// The default implementation of this method does nothing.
|
/// The default implementation of this method does nothing.
|
||||||
#[allow(unused_variables)]
|
#[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]
|
#[crate::async_trait]
|
||||||
|
@ -474,12 +474,12 @@ impl<T: Fairing> Fairing for std::sync::Arc<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[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;
|
(self as &T).on_request(req, data).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[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;
|
(self as &T).on_response(req, res).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
if request.method() == Method::Get {
|
||||||
self.get.fetch_add(1, Ordering::Relaxed);
|
self.get.fetch_add(1, Ordering::Relaxed);
|
||||||
} else if request.method() == Method::Post {
|
} 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 {
|
if res.status() != Status::NotFound {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,7 +169,7 @@ impl Fairing for Counter {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Increment the counter for `GET` and `POST` requests.
|
// 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() {
|
match request.method() {
|
||||||
Method::Get => self.get.fetch_add(1, Ordering::Relaxed),
|
Method::Get => self.get.fetch_add(1, Ordering::Relaxed),
|
||||||
Method::Post => self.post.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.
|
// Don't change a successful user's response, ever.
|
||||||
if response.status() != Status::NotFound {
|
if response.status() != Status::NotFound {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue