From 91f3fc3e8af4523fca46bbf2b0a82919202b4bab Mon Sep 17 00:00:00 2001 From: Fangdun Tsai Date: Fri, 29 Dec 2023 09:33:00 +0800 Subject: [PATCH] feat: remove redundant 'static --- Cargo.toml | 2 +- viz-core/src/handler.rs | 6 +++--- viz-core/src/handler/after.rs | 7 ++----- viz-core/src/handler/and_then.rs | 7 ++----- viz-core/src/handler/around.rs | 4 ++-- viz-core/src/handler/before.rs | 7 ++----- viz-core/src/handler/boxed.rs | 4 ++-- viz-core/src/handler/catch_error.rs | 7 ++----- viz-core/src/handler/catch_unwind.rs | 6 +++--- viz-core/src/handler/either.rs | 4 ++-- viz-core/src/handler/fn_ext.rs | 4 ++-- viz-core/src/handler/fn_ext_hanlder.rs | 5 ++--- viz-core/src/handler/map.rs | 7 ++----- viz-core/src/handler/map_err.rs | 7 ++----- viz-core/src/handler/map_into_response.rs | 7 ++----- viz-core/src/handler/or_else.rs | 7 ++----- viz-core/src/handler/service.rs | 6 +++--- viz-core/src/handler/try_handler.rs | 6 +++--- viz-core/src/lib.rs | 7 +++++-- viz-core/src/middleware/compression.rs | 5 ++--- viz-core/src/middleware/cookie.rs | 5 ++--- viz-core/src/middleware/cors.rs | 6 +++--- viz-core/src/middleware/csrf.rs | 7 +++---- viz-core/src/middleware/limits.rs | 6 +++--- viz-core/src/middleware/otel/metrics.rs | 5 ++--- viz-core/src/middleware/otel/tracing.rs | 6 +++--- viz-core/src/middleware/session/config.rs | 6 +++--- viz-handlers/src/embed.rs | 7 +++---- viz-handlers/src/prometheus.rs | 5 ++--- viz-handlers/src/serve.rs | 8 ++++---- 30 files changed, 74 insertions(+), 102 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7fbd8840..1e1d932b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [workspace] resolver = "2" members = [ - "viz", + # "viz", "viz-core", "viz-handlers", "viz-macros", diff --git a/viz-core/src/handler.rs b/viz-core/src/handler.rs index 5cdfd9d1..0e47e418 100644 --- a/viz-core/src/handler.rs +++ b/viz-core/src/handler.rs @@ -1,6 +1,6 @@ //! Traits and types for handling an HTTP. -use crate::future::{BoxFuture, Future}; +use crate::{BoxFuture, Future}; mod cloneable; pub use cloneable::{BoxCloneable, Cloneable}; @@ -67,7 +67,7 @@ pub trait Handler { type Output; /// Performs the call operation. - fn call(&self, input: Input) -> BoxFuture<'static, Self::Output>; + fn call(&self, input: Input) -> BoxFuture; } impl Handler for F @@ -78,7 +78,7 @@ where { type Output = Fut::Output; - fn call(&self, i: I) -> BoxFuture<'static, Self::Output> { + fn call(&self, i: I) -> BoxFuture { Box::pin((self)(i)) } } diff --git a/viz-core/src/handler/after.rs b/viz-core/src/handler/after.rs index 4f52f476..8201a26e 100644 --- a/viz-core/src/handler/after.rs +++ b/viz-core/src/handler/after.rs @@ -1,7 +1,4 @@ -use crate::{ - future::{BoxFuture, FutureExt}, - Handler, Result, -}; +use crate::{future::FutureExt, BoxFuture, Handler, Result}; /// Maps the output `Result` after the handler called. #[derive(Debug, Clone)] @@ -26,7 +23,7 @@ where { type Output = F::Output; - fn call(&self, i: I) -> BoxFuture<'static, Self::Output> { + fn call(&self, i: I) -> BoxFuture { let f = self.f.clone(); let fut = self.h.call(i).then(move |o| f.call(o)); Box::pin(fut) diff --git a/viz-core/src/handler/and_then.rs b/viz-core/src/handler/and_then.rs index 40cfffca..889b32d0 100644 --- a/viz-core/src/handler/and_then.rs +++ b/viz-core/src/handler/and_then.rs @@ -1,7 +1,4 @@ -use crate::{ - future::{BoxFuture, TryFutureExt}, - Handler, Result, -}; +use crate::{future::TryFutureExt, BoxFuture, Handler, Result}; /// Calls `op` if the output is `Ok`, otherwise returns the `Err` value of the output. #[derive(Debug, Clone)] @@ -26,7 +23,7 @@ where { type Output = F::Output; - fn call(&self, i: I) -> BoxFuture<'static, Self::Output> { + fn call(&self, i: I) -> BoxFuture { let f = self.f.clone(); let fut = self.h.call(i).and_then(move |o| f.call(o)); Box::pin(fut) diff --git a/viz-core/src/handler/around.rs b/viz-core/src/handler/around.rs index 98a0102e..01ae5ea1 100644 --- a/viz-core/src/handler/around.rs +++ b/viz-core/src/handler/around.rs @@ -1,4 +1,4 @@ -use crate::{future::BoxFuture, Handler, Result}; +use crate::{BoxFuture, Handler, Result}; /// Represents a middleware parameter, which is a tuple that includes Requset and `BoxHandler`. pub type Next = (I, H); @@ -26,7 +26,7 @@ where { type Output = F::Output; - fn call(&self, i: I) -> BoxFuture<'static, Self::Output> { + fn call(&self, i: I) -> BoxFuture { let h = self.h.clone(); Box::pin(self.f.call((i, h))) } diff --git a/viz-core/src/handler/before.rs b/viz-core/src/handler/before.rs index 2424a629..d08eae34 100644 --- a/viz-core/src/handler/before.rs +++ b/viz-core/src/handler/before.rs @@ -1,7 +1,4 @@ -use crate::{ - future::{BoxFuture, TryFutureExt}, - Handler, Result, -}; +use crate::{future::TryFutureExt, BoxFuture, Handler, Result}; /// Maps the input before the handler calls. #[derive(Debug, Clone)] @@ -27,7 +24,7 @@ where { type Output = H::Output; - fn call(&self, i: I) -> BoxFuture<'static, Self::Output> { + fn call(&self, i: I) -> BoxFuture { let h = self.h.clone(); let fut = self.f.call(i).and_then(move |i| h.call(i)); Box::pin(fut) diff --git a/viz-core/src/handler/boxed.rs b/viz-core/src/handler/boxed.rs index d4fe0dde..14531d56 100644 --- a/viz-core/src/handler/boxed.rs +++ b/viz-core/src/handler/boxed.rs @@ -1,4 +1,4 @@ -use crate::{future::BoxFuture, handler::BoxCloneable, Handler, Request, Response, Result}; +use crate::{handler::BoxCloneable, BoxFuture, Handler, Request, Response, Result}; pub struct BoxHandler>(BoxCloneable); @@ -20,7 +20,7 @@ impl Clone for BoxHandler { impl Handler for BoxHandler { type Output = O; - fn call(&self, i: I) -> BoxFuture<'static, Self::Output> { + fn call(&self, i: I) -> BoxFuture { self.0.call(i) } } diff --git a/viz-core/src/handler/catch_error.rs b/viz-core/src/handler/catch_error.rs index 3a20909c..c4014382 100644 --- a/viz-core/src/handler/catch_error.rs +++ b/viz-core/src/handler/catch_error.rs @@ -1,9 +1,6 @@ use std::marker::PhantomData; -use crate::{ - future::{BoxFuture, TryFutureExt}, - Error, Handler, IntoResponse, Response, Result, -}; +use crate::{future::TryFutureExt, BoxFuture, Error, Handler, IntoResponse, Response, Result}; /// Catches rejected error while calling the handler. #[derive(Debug)] @@ -49,7 +46,7 @@ where { type Output = Result; - fn call(&self, i: I) -> BoxFuture<'static, Self::Output> { + fn call(&self, i: I) -> BoxFuture { let f = self.f.clone(); let fut = self .h diff --git a/viz-core/src/handler/catch_unwind.rs b/viz-core/src/handler/catch_unwind.rs index 125482f8..6202e017 100644 --- a/viz-core/src/handler/catch_unwind.rs +++ b/viz-core/src/handler/catch_unwind.rs @@ -1,6 +1,6 @@ use crate::{ - future::{BoxFuture, FutureExt, TryFutureExt}, - Handler, IntoResponse, Response, Result, + future::{FutureExt, TryFutureExt}, + BoxFuture, Handler, IntoResponse, Response, Result, }; /// Catches unwinding panics while calling the handler. @@ -27,7 +27,7 @@ where { type Output = Result; - fn call(&self, i: I) -> BoxFuture<'static, Self::Output> { + fn call(&self, i: I) -> BoxFuture { let f = self.f.clone(); let fut = ::core::panic::AssertUnwindSafe(self.h.call(i)) .catch_unwind() diff --git a/viz-core/src/handler/either.rs b/viz-core/src/handler/either.rs index 6de28c17..1b5e130b 100644 --- a/viz-core/src/handler/either.rs +++ b/viz-core/src/handler/either.rs @@ -1,4 +1,4 @@ -use crate::{future::BoxFuture, Handler}; +use crate::{BoxFuture, Handler}; /// Combines two different handlers having the same associated types into a single type. #[derive(Debug, Clone)] @@ -18,7 +18,7 @@ where { type Output = O; - fn call(&self, i: I) -> BoxFuture<'static, Self::Output> { + fn call(&self, i: I) -> BoxFuture { Box::pin(match self { Self::Left(l) => l.call(i), Self::Right(r) => r.call(i), diff --git a/viz-core/src/handler/fn_ext.rs b/viz-core/src/handler/fn_ext.rs index 24b63361..edef9891 100644 --- a/viz-core/src/handler/fn_ext.rs +++ b/viz-core/src/handler/fn_ext.rs @@ -1,4 +1,4 @@ -use crate::{future::BoxFuture, Request}; +use crate::{BoxFuture, Request}; /// A handler with extractors. pub trait FnExt { @@ -6,5 +6,5 @@ pub trait FnExt { type Output; /// Performs the call operation. - fn call(&self, req: Request) -> BoxFuture<'static, Self::Output>; + fn call(&self, req: Request) -> BoxFuture; } diff --git a/viz-core/src/handler/fn_ext_hanlder.rs b/viz-core/src/handler/fn_ext_hanlder.rs index e7cbe074..2075b6aa 100644 --- a/viz-core/src/handler/fn_ext_hanlder.rs +++ b/viz-core/src/handler/fn_ext_hanlder.rs @@ -1,8 +1,7 @@ use std::marker::PhantomData; use crate::{ - future::{BoxFuture, TryFutureExt}, - FnExt, FromRequest, Handler, IntoResponse, Request, Result, + future::TryFutureExt, BoxFuture, FnExt, FromRequest, Handler, IntoResponse, Request, Result, }; /// A wrapper of the extractors handler. @@ -34,7 +33,7 @@ where { type Output = H::Output; - fn call(&self, req: Request) -> BoxFuture<'static, Self::Output> { + fn call(&self, req: Request) -> BoxFuture { let fut = self.0.call(req).map_err(IntoResponse::into_error); Box::pin(fut) } diff --git a/viz-core/src/handler/map.rs b/viz-core/src/handler/map.rs index 5ff6ee6c..5737936f 100644 --- a/viz-core/src/handler/map.rs +++ b/viz-core/src/handler/map.rs @@ -1,7 +1,4 @@ -use crate::{ - future::{BoxFuture, TryFutureExt}, - Handler, Result, -}; +use crate::{future::TryFutureExt, BoxFuture, Handler, Result}; /// Maps the `Ok` value of the output if after the handler called. #[derive(Debug, Clone)] @@ -26,7 +23,7 @@ where { type Output = Result; - fn call(&self, i: I) -> BoxFuture<'static, Self::Output> { + fn call(&self, i: I) -> BoxFuture { let fut = self.h.call(i).map_ok(self.f.clone()); Box::pin(fut) } diff --git a/viz-core/src/handler/map_err.rs b/viz-core/src/handler/map_err.rs index e276393a..2ab536b8 100644 --- a/viz-core/src/handler/map_err.rs +++ b/viz-core/src/handler/map_err.rs @@ -1,7 +1,4 @@ -use crate::{ - future::{BoxFuture, TryFutureExt}, - Error, Handler, Result, -}; +use crate::{future::TryFutureExt, BoxFuture, Error, Handler, Result}; /// Maps the `Err` value of the output if after the handler called. #[derive(Debug, Clone)] @@ -27,7 +24,7 @@ where { type Output = Result; - fn call(&self, i: I) -> BoxFuture<'static, Self::Output> { + fn call(&self, i: I) -> BoxFuture { let fut = self.h.call(i).map_err(self.f.clone()); Box::pin(fut) } diff --git a/viz-core/src/handler/map_into_response.rs b/viz-core/src/handler/map_into_response.rs index dba2d2aa..e4990c66 100644 --- a/viz-core/src/handler/map_into_response.rs +++ b/viz-core/src/handler/map_into_response.rs @@ -1,7 +1,4 @@ -use crate::{ - future::{BoxFuture, TryFutureExt}, - Handler, IntoResponse, Response, Result, -}; +use crate::{future::TryFutureExt, BoxFuture, Handler, IntoResponse, Response, Result}; /// Maps the handler's output type to the [`Response`]. #[derive(Debug, Clone)] @@ -22,7 +19,7 @@ where { type Output = Result; - fn call(&self, i: I) -> BoxFuture<'static, Self::Output> { + fn call(&self, i: I) -> BoxFuture { let fut = self.0.call(i).map_ok(IntoResponse::into_response); Box::pin(fut) } diff --git a/viz-core/src/handler/or_else.rs b/viz-core/src/handler/or_else.rs index c2d16155..54e86608 100644 --- a/viz-core/src/handler/or_else.rs +++ b/viz-core/src/handler/or_else.rs @@ -1,7 +1,4 @@ -use crate::{ - future::{BoxFuture, TryFutureExt}, - Error, Handler, Result, -}; +use crate::{future::TryFutureExt, BoxFuture, Error, Handler, Result}; /// Calls `op` if the output is `Err`, otherwise returns the `Ok` value of the output. #[derive(Debug, Clone)] @@ -26,7 +23,7 @@ where { type Output = F::Output; - fn call(&self, i: I) -> BoxFuture<'static, Self::Output> { + fn call(&self, i: I) -> BoxFuture { let f = self.f.clone(); let fut = self.h.call(i).or_else(move |e| f.call(e)); Box::pin(fut) diff --git a/viz-core/src/handler/service.rs b/viz-core/src/handler/service.rs index ae675cc0..527247f6 100644 --- a/viz-core/src/handler/service.rs +++ b/viz-core/src/handler/service.rs @@ -1,8 +1,8 @@ use hyper::service::Service; use crate::{ - future::{BoxFuture, TryFutureExt}, - Body, BoxError, Bytes, Error, Handler, HttpBody, Request, Response, Result, + future::TryFutureExt, Body, BoxError, BoxFuture, Bytes, Error, Handler, HttpBody, Request, + Response, Result, }; /// Converts a hyper [`Service`] to a viz [`Handler`]. @@ -28,7 +28,7 @@ where { type Output = Result; - fn call(&self, req: Request) -> BoxFuture<'static, Self::Output> { + fn call(&self, req: Request) -> BoxFuture { let fut = self .0 .call(req) diff --git a/viz-core/src/handler/try_handler.rs b/viz-core/src/handler/try_handler.rs index e5ce9db9..109e9c89 100644 --- a/viz-core/src/handler/try_handler.rs +++ b/viz-core/src/handler/try_handler.rs @@ -1,11 +1,11 @@ -use crate::{future::BoxFuture, Handler}; +use crate::{BoxFuture, Handler}; pub trait TryHandler: Handler { type Ok; type Error; - fn try_call(&self, input: Input) -> BoxFuture<'static, Result>; + fn try_call(&self, input: Input) -> BoxFuture>; } impl TryHandler for F @@ -16,7 +16,7 @@ where type Error = E; #[inline] - fn try_call(&self, input: I) -> BoxFuture<'static, Result> { + fn try_call(&self, input: I) -> BoxFuture> { self.call(input) } } diff --git a/viz-core/src/lib.rs b/viz-core/src/lib.rs index 2b214934..3b145713 100644 --- a/viz-core/src/lib.rs +++ b/viz-core/src/lib.rs @@ -43,17 +43,20 @@ pub type Request = http::Request; /// Represents an HTTP Response. pub type Response = http::Response; /// Represents either success (Ok) or failure (Err). -pub type Result = core::result::Result; +pub type Result = ::core::result::Result; +/// An owned dynamically typed [`Future`] for use in cases where you can't +/// statically type your result or need to add some indirection. +pub type BoxFuture = ::core::pin::Pin + Send>>; pub use async_trait::async_trait; pub use bytes::{Bytes, BytesMut}; +pub use core::future::Future; pub use futures_util::future; #[doc(inline)] pub use headers; pub use http::{header, Method, StatusCode}; pub use hyper::body::{Body as HttpBody, Incoming}; pub use hyper_util::rt::TokioIo as Io; -pub use std::future::Future; pub use thiserror::Error as ThisError; #[doc(hidden)] diff --git a/viz-core/src/middleware/compression.rs b/viz-core/src/middleware/compression.rs index 3e4c82a3..071617ac 100644 --- a/viz-core/src/middleware/compression.rs +++ b/viz-core/src/middleware/compression.rs @@ -6,9 +6,8 @@ use async_compression::tokio::bufread; use tokio_util::io::{ReaderStream, StreamReader}; use crate::{ - future::BoxFuture, header::{HeaderValue, ACCEPT_ENCODING, CONTENT_ENCODING, CONTENT_LENGTH}, - Body, Handler, IntoResponse, Request, Response, Result, Transform, + Body, BoxFuture, Handler, IntoResponse, Request, Response, Result, Transform, }; /// Compress response body. @@ -39,7 +38,7 @@ where { type Output = Result; - fn call(&self, req: Request) -> BoxFuture<'static, Self::Output> { + fn call(&self, req: Request) -> BoxFuture { let h = self.h.clone(); Box::pin(async move { diff --git a/viz-core/src/middleware/cookie.rs b/viz-core/src/middleware/cookie.rs index 71ee7cad..55e8bfa7 100644 --- a/viz-core/src/middleware/cookie.rs +++ b/viz-core/src/middleware/cookie.rs @@ -3,10 +3,9 @@ use std::fmt; use crate::{ - future::BoxFuture, header::{HeaderValue, COOKIE, SET_COOKIE}, types::{Cookie, CookieJar, CookieKey, Cookies}, - Handler, IntoResponse, Request, Response, Result, Transform, + BoxFuture, Handler, IntoResponse, Request, Response, Result, Transform, }; /// A configure for [`CookieMiddleware`]. @@ -87,7 +86,7 @@ where { type Output = Result; - fn call(&self, mut req: Request) -> BoxFuture<'static, Self::Output> { + fn call(&self, mut req: Request) -> BoxFuture { let jar = req .headers() .get_all(COOKIE) diff --git a/viz-core/src/middleware/cors.rs b/viz-core/src/middleware/cors.rs index 6b609aea..25f10d49 100644 --- a/viz-core/src/middleware/cors.rs +++ b/viz-core/src/middleware/cors.rs @@ -3,7 +3,6 @@ use std::{collections::HashSet, fmt, sync::Arc}; use crate::{ - future::BoxFuture, header::{ HeaderMap, HeaderName, HeaderValue, ACCESS_CONTROL_ALLOW_CREDENTIALS, ACCESS_CONTROL_ALLOW_HEADERS, ACCESS_CONTROL_ALLOW_ORIGIN, ACCESS_CONTROL_REQUEST_HEADERS, @@ -13,7 +12,8 @@ use crate::{ AccessControlAllowHeaders, AccessControlAllowMethods, AccessControlExposeHeaders, HeaderMapExt, }, - Handler, IntoResponse, Method, Request, RequestExt, Response, Result, StatusCode, Transform, + BoxFuture, Handler, IntoResponse, Method, Request, RequestExt, Response, Result, StatusCode, + Transform, }; /// A configuration for [`CorsMiddleware`]. @@ -210,7 +210,7 @@ where { type Output = Result; - fn call(&self, req: Request) -> BoxFuture<'static, Self::Output> { + fn call(&self, req: Request) -> BoxFuture { let Self { config, acam, diff --git a/viz-core/src/middleware/csrf.rs b/viz-core/src/middleware/csrf.rs index a7a7e68c..fe80319b 100644 --- a/viz-core/src/middleware/csrf.rs +++ b/viz-core/src/middleware/csrf.rs @@ -6,11 +6,10 @@ use base64::Engine as _; use crate::{ async_trait, - future::BoxFuture, header::{HeaderName, HeaderValue, VARY}, middleware::helper::{CookieOptions, Cookieable}, - Error, FromRequest, Handler, IntoResponse, Method, Request, RequestExt, Response, Result, - StatusCode, Transform, + BoxFuture, Error, FromRequest, Handler, IntoResponse, Method, Request, RequestExt, Response, + Result, StatusCode, Transform, }; #[derive(Debug)] @@ -197,7 +196,7 @@ where { type Output = Result; - fn call(&self, mut req: Request) -> BoxFuture<'static, Self::Output> { + fn call(&self, mut req: Request) -> BoxFuture { let Self { config, h } = self.clone(); Box::pin(async move { diff --git a/viz-core/src/middleware/limits.rs b/viz-core/src/middleware/limits.rs index 8c7a7315..299b6f1f 100644 --- a/viz-core/src/middleware/limits.rs +++ b/viz-core/src/middleware/limits.rs @@ -4,8 +4,8 @@ use std::sync::Arc; use crate::{ - future::{BoxFuture, TryFutureExt}, - types, Handler, IntoResponse, Request, Response, Result, Transform, + future::TryFutureExt, types, BoxFuture, Handler, IntoResponse, Request, Response, Result, + Transform, }; /// A configuration for [`LimitsMiddleware`]. @@ -77,7 +77,7 @@ where { type Output = Result; - fn call(&self, mut req: Request) -> BoxFuture<'static, Self::Output> { + fn call(&self, mut req: Request) -> BoxFuture { req.extensions_mut().insert(self.config.limits.clone()); #[cfg(feature = "multipart")] req.extensions_mut().insert(self.config.multipart.clone()); diff --git a/viz-core/src/middleware/otel/metrics.rs b/viz-core/src/middleware/otel/metrics.rs index 5a1e1124..e798bb75 100644 --- a/viz-core/src/middleware/otel/metrics.rs +++ b/viz-core/src/middleware/otel/metrics.rs @@ -15,8 +15,7 @@ use opentelemetry_semantic_conventions::trace::{ }; use crate::{ - future::BoxFuture, Handler, IntoResponse, Request, RequestExt, Response, ResponseExt, Result, - Transform, + BoxFuture, Handler, IntoResponse, Request, RequestExt, Response, ResponseExt, Result, Transform, }; const HTTP_SERVER_ACTIVE_REQUESTS: &str = "http.server.active_requests"; @@ -103,7 +102,7 @@ where { type Output = Result; - fn call(&self, req: Request) -> BoxFuture<'static, Self::Output> { + fn call(&self, req: Request) -> BoxFuture { let Self { active_requests, duration, diff --git a/viz-core/src/middleware/otel/tracing.rs b/viz-core/src/middleware/otel/tracing.rs index 7ab9c47a..b2dbb501 100644 --- a/viz-core/src/middleware/otel/tracing.rs +++ b/viz-core/src/middleware/otel/tracing.rs @@ -19,10 +19,10 @@ use opentelemetry_semantic_conventions::trace::{ }; use crate::{ - future::BoxFuture, header::{HeaderMap, HeaderName}, headers::UserAgent, - Handler, IntoResponse, Request, RequestExt, Response, ResponseExt, Result, Transform, + BoxFuture, Handler, IntoResponse, Request, RequestExt, Response, ResponseExt, Result, + Transform, }; /// `OpenTelemetry` tracing config. @@ -67,7 +67,7 @@ where { type Output = Result; - fn call(&self, req: Request) -> BoxFuture<'static, Self::Output> { + fn call(&self, req: Request) -> BoxFuture { let Self { tracer, h } = self.clone(); Box::pin(async move { diff --git a/viz-core/src/middleware/session/config.rs b/viz-core/src/middleware/session/config.rs index 1974b15c..ccdb45d6 100644 --- a/viz-core/src/middleware/session/config.rs +++ b/viz-core/src/middleware/session/config.rs @@ -5,10 +5,10 @@ use std::{ }; use crate::{ - future::BoxFuture, middleware::helper::{CookieOptions, Cookieable}, types::{Cookie, Session}, - Error, Handler, IntoResponse, Request, RequestExt, Response, Result, StatusCode, Transform, + BoxFuture, Error, Handler, IntoResponse, Request, RequestExt, Response, Result, StatusCode, + Transform, }; use super::{Error as SessionError, Storage, Store, PURGED, RENEWED, UNCHANGED}; @@ -99,7 +99,7 @@ where { type Output = Result; - fn call(&self, mut req: Request) -> BoxFuture<'static, Self::Output> { + fn call(&self, mut req: Request) -> BoxFuture { let Self { config, h } = self.clone(); Box::pin(async move { diff --git a/viz-handlers/src/embed.rs b/viz-handlers/src/embed.rs index f053712c..37089ca6 100644 --- a/viz-handlers/src/embed.rs +++ b/viz-handlers/src/embed.rs @@ -5,9 +5,8 @@ use std::{borrow::Cow, marker::PhantomData}; use http_body_util::Full; use rust_embed::{EmbeddedFile, RustEmbed}; use viz_core::{ - future::BoxFuture, header::{CONTENT_TYPE, ETAG, IF_NONE_MATCH}, - Handler, IntoResponse, Method, Request, RequestExt, Response, Result, StatusCode, + BoxFuture, Handler, IntoResponse, Method, Request, RequestExt, Response, Result, StatusCode, }; /// Serve a single embedded file. @@ -34,7 +33,7 @@ where { type Output = Result; - fn call(&self, req: Request) -> BoxFuture<'static, Self::Output> { + fn call(&self, req: Request) -> BoxFuture { Box::pin(serve::(self.0.to_string(), req)) } } @@ -61,7 +60,7 @@ where { type Output = Result; - fn call(&self, req: Request) -> BoxFuture<'static, Self::Output> { + fn call(&self, req: Request) -> BoxFuture { let path = match req.route_info().params.first().map(|(_, v)| v) { Some(p) => p, None => "index.html", diff --git a/viz-handlers/src/prometheus.rs b/viz-handlers/src/prometheus.rs index 8a1bc728..7dc6594d 100644 --- a/viz-handlers/src/prometheus.rs +++ b/viz-handlers/src/prometheus.rs @@ -7,9 +7,8 @@ use opentelemetry::{global::handle_error, metrics::MetricsError}; use prometheus::{Encoder, TextEncoder}; use viz_core::{ - future::BoxFuture, header::{HeaderValue, CONTENT_TYPE}, - Handler, IntoResponse, Request, Response, Result, StatusCode, + BoxFuture, Handler, IntoResponse, Request, Response, Result, StatusCode, }; #[doc(inline)] @@ -34,7 +33,7 @@ impl Prometheus { impl Handler for Prometheus { type Output = Result; - fn call(&self, _: Request) -> BoxFuture<'static, Self::Output> { + fn call(&self, _: Request) -> BoxFuture { let Self { registry } = self.clone(); Box::pin(async move { diff --git a/viz-handlers/src/serve.rs b/viz-handlers/src/serve.rs index aaca0c63..e80a331f 100644 --- a/viz-handlers/src/serve.rs +++ b/viz-handlers/src/serve.rs @@ -11,12 +11,12 @@ use tokio::io::AsyncReadExt; use tokio_util::io::ReaderStream; use viz_core::{ - future::BoxFuture, headers::{ AcceptRanges, ContentLength, ContentRange, ContentType, ETag, HeaderMap, HeaderMapExt, IfMatch, IfModifiedSince, IfNoneMatch, IfUnmodifiedSince, LastModified, Range, }, - Handler, IntoResponse, Method, Request, RequestExt, Response, ResponseExt, Result, StatusCode, + BoxFuture, Handler, IntoResponse, Method, Request, RequestExt, Response, ResponseExt, Result, + StatusCode, }; mod directory; @@ -50,7 +50,7 @@ impl File { impl Handler for File { type Output = Result; - fn call(&self, req: Request) -> BoxFuture<'static, Self::Output> { + fn call(&self, req: Request) -> BoxFuture { let path = self.path.clone(); Box::pin(async move { serve(&path, req.headers()) }) } @@ -101,7 +101,7 @@ impl Dir { impl Handler for Dir { type Output = Result; - fn call(&self, req: Request) -> BoxFuture<'static, Self::Output> { + fn call(&self, req: Request) -> BoxFuture { let Self { mut path, listing,