Skip to content

Commit

Permalink
feat: remove redundant 'static
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Dec 29, 2023
1 parent 84ece0e commit 91f3fc3
Show file tree
Hide file tree
Showing 30 changed files with 74 additions and 102 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[workspace]
resolver = "2"
members = [
"viz",
# "viz",
"viz-core",
"viz-handlers",
"viz-macros",
Expand Down
6 changes: 3 additions & 3 deletions viz-core/src/handler.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -67,7 +67,7 @@ pub trait Handler<Input> {
type Output;

/// Performs the call operation.
fn call(&self, input: Input) -> BoxFuture<'static, Self::Output>;
fn call(&self, input: Input) -> BoxFuture<Self::Output>;
}

impl<F, I, Fut, O> Handler<I> for F
Expand All @@ -78,7 +78,7 @@ where
{
type Output = Fut::Output;

fn call(&self, i: I) -> BoxFuture<'static, Self::Output> {
fn call(&self, i: I) -> BoxFuture<Self::Output> {
Box::pin((self)(i))
}
}
Expand Down
7 changes: 2 additions & 5 deletions viz-core/src/handler/after.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
future::{BoxFuture, FutureExt},
Handler, Result,
};
use crate::{future::FutureExt, BoxFuture, Handler, Result};

/// Maps the output `Result<T>` after the handler called.
#[derive(Debug, Clone)]
Expand All @@ -26,7 +23,7 @@ where
{
type Output = F::Output;

fn call(&self, i: I) -> BoxFuture<'static, Self::Output> {
fn call(&self, i: I) -> BoxFuture<Self::Output> {
let f = self.f.clone();
let fut = self.h.call(i).then(move |o| f.call(o));
Box::pin(fut)
Expand Down
7 changes: 2 additions & 5 deletions viz-core/src/handler/and_then.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -26,7 +23,7 @@ where
{
type Output = F::Output;

fn call(&self, i: I) -> BoxFuture<'static, Self::Output> {
fn call(&self, i: I) -> BoxFuture<Self::Output> {
let f = self.f.clone();
let fut = self.h.call(i).and_then(move |o| f.call(o));
Box::pin(fut)
Expand Down
4 changes: 2 additions & 2 deletions viz-core/src/handler/around.rs
Original file line number Diff line number Diff line change
@@ -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> = (I, H);
Expand Down Expand Up @@ -26,7 +26,7 @@ where
{
type Output = F::Output;

fn call(&self, i: I) -> BoxFuture<'static, Self::Output> {
fn call(&self, i: I) -> BoxFuture<Self::Output> {
let h = self.h.clone();
Box::pin(self.f.call((i, h)))
}
Expand Down
7 changes: 2 additions & 5 deletions viz-core/src/handler/before.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -27,7 +24,7 @@ where
{
type Output = H::Output;

fn call(&self, i: I) -> BoxFuture<'static, Self::Output> {
fn call(&self, i: I) -> BoxFuture<Self::Output> {
let h = self.h.clone();
let fut = self.f.call(i).and_then(move |i| h.call(i));
Box::pin(fut)
Expand Down
4 changes: 2 additions & 2 deletions viz-core/src/handler/boxed.rs
Original file line number Diff line number Diff line change
@@ -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<I = Request, O = Result<Response>>(BoxCloneable<I, O>);

Expand All @@ -20,7 +20,7 @@ impl<I, O> Clone for BoxHandler<I, O> {
impl<I, O> Handler<I> for BoxHandler<I, O> {
type Output = O;

fn call(&self, i: I) -> BoxFuture<'static, Self::Output> {
fn call(&self, i: I) -> BoxFuture<Self::Output> {
self.0.call(i)
}
}
Expand Down
7 changes: 2 additions & 5 deletions viz-core/src/handler/catch_error.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -49,7 +46,7 @@ where
{
type Output = Result<Response>;

fn call(&self, i: I) -> BoxFuture<'static, Self::Output> {
fn call(&self, i: I) -> BoxFuture<Self::Output> {
let f = self.f.clone();
let fut = self
.h
Expand Down
6 changes: 3 additions & 3 deletions viz-core/src/handler/catch_unwind.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -27,7 +27,7 @@ where
{
type Output = Result<Response>;

fn call(&self, i: I) -> BoxFuture<'static, Self::Output> {
fn call(&self, i: I) -> BoxFuture<Self::Output> {
let f = self.f.clone();
let fut = ::core::panic::AssertUnwindSafe(self.h.call(i))
.catch_unwind()
Expand Down
4 changes: 2 additions & 2 deletions viz-core/src/handler/either.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -18,7 +18,7 @@ where
{
type Output = O;

fn call(&self, i: I) -> BoxFuture<'static, Self::Output> {
fn call(&self, i: I) -> BoxFuture<Self::Output> {
Box::pin(match self {
Self::Left(l) => l.call(i),
Self::Right(r) => r.call(i),
Expand Down
4 changes: 2 additions & 2 deletions viz-core/src/handler/fn_ext.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{future::BoxFuture, Request};
use crate::{BoxFuture, Request};

/// A handler with extractors.
pub trait FnExt<E> {
/// The returned type after the call operator is used.
type Output;

/// Performs the call operation.
fn call(&self, req: Request) -> BoxFuture<'static, Self::Output>;
fn call(&self, req: Request) -> BoxFuture<Self::Output>;
}
5 changes: 2 additions & 3 deletions viz-core/src/handler/fn_ext_hanlder.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -34,7 +33,7 @@ where
{
type Output = H::Output;

fn call(&self, req: Request) -> BoxFuture<'static, Self::Output> {
fn call(&self, req: Request) -> BoxFuture<Self::Output> {
let fut = self.0.call(req).map_err(IntoResponse::into_error);
Box::pin(fut)
}
Expand Down
7 changes: 2 additions & 5 deletions viz-core/src/handler/map.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -26,7 +23,7 @@ where
{
type Output = Result<T>;

fn call(&self, i: I) -> BoxFuture<'static, Self::Output> {
fn call(&self, i: I) -> BoxFuture<Self::Output> {
let fut = self.h.call(i).map_ok(self.f.clone());
Box::pin(fut)
}
Expand Down
7 changes: 2 additions & 5 deletions viz-core/src/handler/map_err.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -27,7 +24,7 @@ where
{
type Output = Result<O>;

fn call(&self, i: I) -> BoxFuture<'static, Self::Output> {
fn call(&self, i: I) -> BoxFuture<Self::Output> {
let fut = self.h.call(i).map_err(self.f.clone());
Box::pin(fut)
}
Expand Down
7 changes: 2 additions & 5 deletions viz-core/src/handler/map_into_response.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -22,7 +19,7 @@ where
{
type Output = Result<Response>;

fn call(&self, i: I) -> BoxFuture<'static, Self::Output> {
fn call(&self, i: I) -> BoxFuture<Self::Output> {
let fut = self.0.call(i).map_ok(IntoResponse::into_response);
Box::pin(fut)
}
Expand Down
7 changes: 2 additions & 5 deletions viz-core/src/handler/or_else.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -26,7 +23,7 @@ where
{
type Output = F::Output;

fn call(&self, i: I) -> BoxFuture<'static, Self::Output> {
fn call(&self, i: I) -> BoxFuture<Self::Output> {
let f = self.f.clone();
let fut = self.h.call(i).or_else(move |e| f.call(e));
Box::pin(fut)
Expand Down
6 changes: 3 additions & 3 deletions viz-core/src/handler/service.rs
Original file line number Diff line number Diff line change
@@ -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`].
Expand All @@ -28,7 +28,7 @@ where
{
type Output = Result<Response>;

fn call(&self, req: Request<I>) -> BoxFuture<'static, Self::Output> {
fn call(&self, req: Request<I>) -> BoxFuture<Self::Output> {
let fut = self
.0
.call(req)
Expand Down
6 changes: 3 additions & 3 deletions viz-core/src/handler/try_handler.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::{future::BoxFuture, Handler};
use crate::{BoxFuture, Handler};

pub trait TryHandler<Input>: Handler<Input> {
type Ok;

type Error;

fn try_call(&self, input: Input) -> BoxFuture<'static, Result<Self::Ok, Self::Error>>;
fn try_call(&self, input: Input) -> BoxFuture<Result<Self::Ok, Self::Error>>;
}

impl<F, I, O, E> TryHandler<I> for F
Expand All @@ -16,7 +16,7 @@ where
type Error = E;

#[inline]
fn try_call(&self, input: I) -> BoxFuture<'static, Result<Self::Ok, Self::Error>> {
fn try_call(&self, input: I) -> BoxFuture<Result<Self::Ok, Self::Error>> {
self.call(input)
}
}
Expand Down
7 changes: 5 additions & 2 deletions viz-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,20 @@ pub type Request<T = Body> = http::Request<T>;
/// Represents an HTTP Response.
pub type Response<T = Body> = http::Response<T>;
/// Represents either success (Ok) or failure (Err).
pub type Result<T, E = Error> = core::result::Result<T, E>;
pub type Result<T, E = Error> = ::core::result::Result<T, E>;
/// 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<T> = ::core::pin::Pin<Box<dyn Future<Output = T> + 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)]
Expand Down
5 changes: 2 additions & 3 deletions viz-core/src/middleware/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -39,7 +38,7 @@ where
{
type Output = Result<Response>;

fn call(&self, req: Request) -> BoxFuture<'static, Self::Output> {
fn call(&self, req: Request) -> BoxFuture<Self::Output> {
let h = self.h.clone();

Box::pin(async move {
Expand Down
5 changes: 2 additions & 3 deletions viz-core/src/middleware/cookie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
Expand Down Expand Up @@ -87,7 +86,7 @@ where
{
type Output = Result<Response>;

fn call(&self, mut req: Request) -> BoxFuture<'static, Self::Output> {
fn call(&self, mut req: Request) -> BoxFuture<Self::Output> {
let jar = req
.headers()
.get_all(COOKIE)
Expand Down
Loading

0 comments on commit 91f3fc3

Please sign in to comment.