Don't internally Arc the state (#1460)

This commit is contained in:
David Pedersen
2022-10-09 20:55:28 +00:00
committed by GitHub
parent a2ab338e68
commit f9dc96fdce
18 changed files with 206 additions and 185 deletions
+4 -8
View File
@@ -6,7 +6,7 @@ use axum::{
response::{IntoResponse, Response},
};
use futures_util::future::{BoxFuture, FutureExt, Map};
use std::{future::Future, marker::PhantomData, sync::Arc};
use std::{future::Future, marker::PhantomData};
mod or;
@@ -24,11 +24,7 @@ pub trait HandlerCallWithExtractors<T, S, B>: Sized {
type Future: Future<Output = Response> + Send + 'static;
/// Call the handler with the extracted inputs.
fn call(
self,
extractors: T,
state: Arc<S>,
) -> <Self as HandlerCallWithExtractors<T, S, B>>::Future;
fn call(self, extractors: T, state: S) -> <Self as HandlerCallWithExtractors<T, S, B>>::Future;
/// Conver this `HandlerCallWithExtractors` into [`Handler`].
fn into_handler(self) -> IntoHandler<Self, T, S, B> {
@@ -133,7 +129,7 @@ macro_rules! impl_handler_call_with {
fn call(
self,
($($ty,)*): ($($ty,)*),
_state: Arc<S>,
_state: S,
) -> <Self as HandlerCallWithExtractors<($($ty,)*), S, B>>::Future {
self($($ty,)*).map(IntoResponse::into_response)
}
@@ -178,7 +174,7 @@ where
{
type Future = BoxFuture<'static, Response>;
fn call(self, req: http::Request<B>, state: Arc<S>) -> Self::Future {
fn call(self, req: http::Request<B>, state: S) -> Self::Future {
Box::pin(async move {
match T::from_request(req, &state).await {
Ok(t) => self.handler.call(t, state).await,
+3 -3
View File
@@ -7,7 +7,7 @@ use axum::{
response::{IntoResponse, Response},
};
use futures_util::future::{BoxFuture, Either as EitherFuture, FutureExt, Map};
use std::{future::Future, marker::PhantomData, sync::Arc};
use std::{future::Future, marker::PhantomData};
/// [`Handler`] that runs one [`Handler`] and if that rejects it'll fallback to another
/// [`Handler`].
@@ -37,7 +37,7 @@ where
fn call(
self,
extractors: Either<Lt, Rt>,
state: Arc<S>,
state: S,
) -> <Self as HandlerCallWithExtractors<Either<Lt, Rt>, S, B>>::Future {
match extractors {
Either::E1(lt) => self
@@ -68,7 +68,7 @@ where
// this puts `futures_util` in our public API but thats fine in axum-extra
type Future = BoxFuture<'static, Response>;
fn call(self, req: Request<B>, state: Arc<S>) -> Self::Future {
fn call(self, req: Request<B>, state: S) -> Self::Future {
Box::pin(async move {
let (mut parts, body) = req.into_parts();