diff --git a/Cargo.toml b/Cargo.toml index 7fbd8840..cac783a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,7 +44,7 @@ homepage = "https://viz.rs" documentation = "https://docs.rs/viz" repository = "https://github.com/viz-rs/viz" license = "MIT" -rust-version = "1.63" # follows `tokio` and `hyper` +rust-version = "1.75" [workspace.dependencies] viz = { version = "0.7.1", path = "viz" } diff --git a/viz-core/src/from_request.rs b/viz-core/src/from_request.rs index 130e48bc..07068224 100644 --- a/viz-core/src/from_request.rs +++ b/viz-core/src/from_request.rs @@ -1,18 +1,17 @@ //! Extracts data from the [`Request`] by types. -use crate::{IntoResponse, Request}; +use crate::{Future, IntoResponse, Request}; /// An interface for extracting data from the HTTP [`Request`]. -#[crate::async_trait] pub trait FromRequest: Sized { /// The type returned in the event of a conversion error. type Error: IntoResponse; /// Extracts this type from the HTTP [`Request`]. - async fn extract(req: &mut Request) -> Result; + #[must_use] + fn extract(req: &mut Request) -> impl Future> + Send; } -#[crate::async_trait] impl FromRequest for Option where T: FromRequest, @@ -24,7 +23,6 @@ where } } -#[crate::async_trait] impl FromRequest for Result where T: FromRequest, diff --git a/viz-core/src/handler/boxed.rs b/viz-core/src/handler/boxed.rs index 43ea69aa..f06acb35 100644 --- a/viz-core/src/handler/boxed.rs +++ b/viz-core/src/handler/boxed.rs @@ -10,7 +10,7 @@ impl BoxHandler { /// Creates a new `BoxHandler`. pub fn new(h: H) -> Self where - H: Handler + Send + Sync + Clone + 'static, + H: Handler + Clone, { Self(Box::new(h)) } diff --git a/viz-core/src/macros.rs b/viz-core/src/macros.rs index 577e20e2..8ca47861 100644 --- a/viz-core/src/macros.rs +++ b/viz-core/src/macros.rs @@ -8,7 +8,6 @@ macro_rules! tuple_impls { }; // "Private" internal implementation (@impl $( $T:ident )*) => { - #[crate::async_trait] impl<$($T,)*> FromRequest for ($($T,)*) where $($T: FromRequest + Send,)* diff --git a/viz-core/src/middleware/csrf.rs b/viz-core/src/middleware/csrf.rs index 4fd62c32..fff98200 100644 --- a/viz-core/src/middleware/csrf.rs +++ b/viz-core/src/middleware/csrf.rs @@ -36,7 +36,6 @@ pub enum Store { #[derive(Debug, Clone)] pub struct CsrfToken(pub String); -#[crate::async_trait] impl FromRequest for CsrfToken { type Error = Error; diff --git a/viz-core/src/request.rs b/viz-core/src/request.rs index 70aae7e9..729de022 100644 --- a/viz-core/src/request.rs +++ b/viz-core/src/request.rs @@ -1,7 +1,7 @@ use crate::{ header, types::{PayloadError, RealIp}, - Body, BodyState, Bytes, FromRequest, Request, Result, + Body, BodyState, Bytes, FromRequest, Future, Request, Result, }; use headers::HeaderMapExt; use http_body_util::{BodyExt, Collected}; @@ -36,7 +36,6 @@ use crate::types::Session; use crate::types::{ParamsError, PathDeserializer, RouteInfo}; /// The [`Request`] Extension. -#[crate::async_trait] pub trait RequestExt: private::Sealed + Sized { /// Get URL's schema of this request. fn schema(&self) -> Option<&http::uri::Scheme>; @@ -75,7 +74,7 @@ pub trait RequestExt: private::Sealed + Sized { fn content_type(&self) -> Option; /// Extract the data from this request by the specified type. - async fn extract(&mut self) -> Result + fn extract(&mut self) -> impl Future> + Send where T: FromRequest; @@ -90,25 +89,29 @@ pub trait RequestExt: private::Sealed + Sized { /// Return with a [Bytes][mdn] representation of the request body. /// /// [mdn]: - async fn bytes(&mut self) -> Result; + fn bytes(&mut self) -> impl Future> + Send; /// Return with a [Bytes][mdn] by a limit representation of the request body. /// /// [mdn]: #[cfg(feature = "limits")] - async fn bytes_with(&mut self, limit: Option, max: u64) -> Result; + fn bytes_with( + &mut self, + limit: Option, + max: u64, + ) -> impl Future> + Send; /// Return with a [Text][mdn] representation of the request body. /// /// [mdn]: - async fn text(&mut self) -> Result; + fn text(&mut self) -> impl Future> + Send; /// Return with a `application/x-www-form-urlencoded` [FormData][mdn] by the specified type /// representation of the request body. /// /// [mdn]: #[cfg(feature = "form")] - async fn form(&mut self) -> Result + fn form(&mut self) -> impl Future> + Send where T: serde::de::DeserializeOwned; @@ -116,7 +119,7 @@ pub trait RequestExt: private::Sealed + Sized { /// /// [mdn]: #[cfg(feature = "json")] - async fn json(&mut self) -> Result + fn json(&mut self) -> impl Future> + Send where T: serde::de::DeserializeOwned; @@ -125,7 +128,7 @@ pub trait RequestExt: private::Sealed + Sized { /// /// [mdn]: #[cfg(feature = "multipart")] - async fn multipart(&mut self) -> Result; + fn multipart(&mut self) -> impl Future> + Send; /// Return a shared state by the specified type. #[cfg(feature = "state")] @@ -193,7 +196,6 @@ pub trait RequestExt: private::Sealed + Sized { fn realip(&self) -> Option; } -#[crate::async_trait] impl RequestExt for Request { fn schema(&self) -> Option<&http::uri::Scheme> { self.uri().scheme() diff --git a/viz-core/src/response.rs b/viz-core/src/response.rs index 18ce6a1e..094b64b1 100644 --- a/viz-core/src/response.rs +++ b/viz-core/src/response.rs @@ -1,10 +1,9 @@ use futures_util::Stream; use http_body_util::Full; -use crate::{header, Body, BoxError, Bytes, Error, Response, Result, StatusCode}; +use crate::{header, Body, BoxError, Bytes, Error, Future, Response, Result, StatusCode}; /// The [`Response`] Extension. -#[crate::async_trait] pub trait ResponseExt: private::Sealed + Sized { /// Get the size of this response's body. fn content_length(&self) -> Option; @@ -96,7 +95,7 @@ pub trait ResponseExt: private::Sealed + Sized { /// Downloads transfers the file from path as an attachment. #[cfg(feature = "fs")] - async fn download(path: T, name: Option<&str>) -> Result + fn download(path: T, name: Option<&str>) -> impl Future> + Send where T: AsRef + Send; @@ -186,7 +185,6 @@ pub trait ResponseExt: private::Sealed + Sized { } } -#[crate::async_trait] impl ResponseExt for Response { fn content_length(&self) -> Option { self.headers() diff --git a/viz-core/src/types/cookie.rs b/viz-core/src/types/cookie.rs index 5199ed34..0d5d3132 100644 --- a/viz-core/src/types/cookie.rs +++ b/viz-core/src/types/cookie.rs @@ -192,7 +192,6 @@ impl Cookies { } } -#[crate::async_trait] impl FromRequest for Cookies { type Error = CookiesError; diff --git a/viz-core/src/types/form.rs b/viz-core/src/types/form.rs index 9eb14ed9..6a7b0b79 100644 --- a/viz-core/src/types/form.rs +++ b/viz-core/src/types/form.rs @@ -81,7 +81,6 @@ impl Payload for Form { } } -#[crate::async_trait] impl FromRequest for Form where T: DeserializeOwned, diff --git a/viz-core/src/types/header.rs b/viz-core/src/types/header.rs index 27aa4694..d9195918 100644 --- a/viz-core/src/types/header.rs +++ b/viz-core/src/types/header.rs @@ -66,7 +66,6 @@ where } } -#[crate::async_trait] impl FromRequest for Header where T: headers::Header, diff --git a/viz-core/src/types/json.rs b/viz-core/src/types/json.rs index 96a2083a..04c3fc47 100644 --- a/viz-core/src/types/json.rs +++ b/viz-core/src/types/json.rs @@ -80,7 +80,6 @@ impl Payload for Json { } } -#[crate::async_trait] impl FromRequest for Json where T: serde::de::DeserializeOwned, diff --git a/viz-core/src/types/limits.rs b/viz-core/src/types/limits.rs index 821fb524..ae189fc4 100644 --- a/viz-core/src/types/limits.rs +++ b/viz-core/src/types/limits.rs @@ -81,7 +81,6 @@ impl Limits { } } -#[crate::async_trait] impl FromRequest for Limits { type Error = Infallible; diff --git a/viz-core/src/types/multipart.rs b/viz-core/src/types/multipart.rs index 209e05e6..6b5155be 100644 --- a/viz-core/src/types/multipart.rs +++ b/viz-core/src/types/multipart.rs @@ -26,7 +26,6 @@ impl Payload for Multipart { } } -#[crate::async_trait] impl FromRequest for Multipart { type Error = PayloadError; diff --git a/viz-core/src/types/params.rs b/viz-core/src/types/params.rs index e5daf16a..615e34f2 100644 --- a/viz-core/src/types/params.rs +++ b/viz-core/src/types/params.rs @@ -76,7 +76,6 @@ impl Params { } } -#[crate::async_trait] impl FromRequest for Params where T: DeserializeOwned, diff --git a/viz-core/src/types/query.rs b/viz-core/src/types/query.rs index 3026e06c..fe1c756e 100644 --- a/viz-core/src/types/query.rs +++ b/viz-core/src/types/query.rs @@ -64,7 +64,6 @@ where } } -#[crate::async_trait] impl FromRequest for Query where T: DeserializeOwned, diff --git a/viz-core/src/types/session.rs b/viz-core/src/types/session.rs index 10d8d1be..fbef5a31 100644 --- a/viz-core/src/types/session.rs +++ b/viz-core/src/types/session.rs @@ -170,7 +170,6 @@ impl fmt::Debug for Session { } } -#[crate::async_trait] impl FromRequest for Session { type Error = Infallible; diff --git a/viz-core/src/types/state.rs b/viz-core/src/types/state.rs index b4ee6020..396bf44f 100644 --- a/viz-core/src/types/state.rs +++ b/viz-core/src/types/state.rs @@ -49,7 +49,6 @@ impl DerefMut for State { } } -#[crate::async_trait] impl FromRequest for State where T: Clone + Send + Sync + 'static, diff --git a/viz-core/src/types/websocket.rs b/viz-core/src/types/websocket.rs index 675446df..ee8c37de 100644 --- a/viz-core/src/types/websocket.rs +++ b/viz-core/src/types/websocket.rs @@ -98,7 +98,6 @@ impl WebSocket { } } -#[crate::async_trait] impl FromRequest for WebSocket { type Error = WebSocketError; diff --git a/viz-core/tests/from_request.rs b/viz-core/tests/from_request.rs index 5853a852..ac2a00a5 100644 --- a/viz-core/tests/from_request.rs +++ b/viz-core/tests/from_request.rs @@ -2,7 +2,7 @@ use headers::HeaderValue; use viz_core::{ header::{CONTENT_LENGTH, CONTENT_TYPE}, types::{Form, Json, Limits, PayloadError, State, StateError}, - Body, FromRequest, Request, RequestExt, Result, + Body, Request, RequestExt, Result, }; #[tokio::test] @@ -16,7 +16,7 @@ async fn from_request() -> Result<()> { .body(Body::Empty)?; req.extensions_mut().insert(Limits::default()); - let result: Result>, PayloadError> = FromRequest::extract(&mut req).await; + let result: Result>, PayloadError> = req.extract().await; assert!(result.is_err()); let mut req = Request::builder() diff --git a/viz-core/tests/handler.rs b/viz-core/tests/handler.rs index 7311b3d4..ff776b40 100644 --- a/viz-core/tests/handler.rs +++ b/viz-core/tests/handler.rs @@ -22,18 +22,16 @@ async fn handler() -> Result<()> { struct MyU8(u8); - #[async_trait] impl FromRequest for MyU8 { type Error = std::convert::Infallible; - async fn extract(_req: &mut Request) -> Result { + async fn extract(_: &mut Request) -> Result { Ok(MyU8(u8::MAX)) } } struct MyString(String); - #[async_trait] impl FromRequest for MyString { type Error = std::convert::Infallible; diff --git a/viz-macros/tests/handler.rs b/viz-macros/tests/handler.rs index 013ac8a4..e4b2b692 100644 --- a/viz-macros/tests/handler.rs +++ b/viz-macros/tests/handler.rs @@ -1,15 +1,12 @@ #![allow(clippy::unused_async)] #![allow(clippy::unnecessary_wraps)] -use viz_core::{ - async_trait, Error, FromRequest, Handler, IntoResponse, Request, Result, StatusCode, -}; +use viz_core::{Error, FromRequest, Handler, IntoResponse, Request, Result, StatusCode}; use viz_macros::handler; #[derive(Debug)] struct Foo; -#[async_trait] impl FromRequest for Foo { type Error = Error; @@ -21,7 +18,6 @@ impl FromRequest for Foo { #[derive(Debug)] struct Bar; -#[async_trait] impl FromRequest for Bar { type Error = Error; diff --git a/viz/src/lib.rs b/viz/src/lib.rs index ca4c2206..9b197794 100644 --- a/viz/src/lib.rs +++ b/viz/src/lib.rs @@ -342,10 +342,9 @@ //! //! ``` //! # use std::{cmp, convert::Infallible}; -//! # use viz::{async_trait, FromRequest, Request, RequestExt, Result}; +//! # use viz::{FromRequest, Request, RequestExt, Result}; //! struct Counter(u16); //! -//! #[async_trait] //! impl FromRequest for Counter { //! type Error = Infallible; //! async fn extract(req: &mut Request) -> Result {