Skip to content

Commit

Permalink
Port most things in axum-extra (#1282)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpdrsn authored Aug 19, 2022
1 parent 75cdd09 commit 69e7164
Show file tree
Hide file tree
Showing 10 changed files with 370 additions and 369 deletions.
4 changes: 2 additions & 2 deletions axum-extra/src/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ macro_rules! impl_traits_for_either {
where
$($ident: FromRequestParts<S>),*,
$last: FromRequest<S, B>,
B: Send,
B: Send + 'static,
S: Send + Sync,
{
type Rejection = $last::Rejection;
Expand Down Expand Up @@ -225,7 +225,7 @@ macro_rules! impl_traits_for_either {

async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
$(
if let Ok(value) = FromRequestParts::from_request_parts(&mut parts, state).await {
if let Ok(value) = FromRequestParts::from_request_parts(parts, state).await {
return Ok(Self::$ident(value));
}
)*
Expand Down
5 changes: 2 additions & 3 deletions axum-extra/src/extract/cached.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,12 @@ where
type Rejection = T::Rejection;

async fn from_request(req: Request<B>, state: &S) -> Result<Self, Self::Rejection> {
let (mut parts, body) = req.into_parts();
let (mut parts, _) = req.into_parts();

match Extension::<CachedEntry<T>>::from_request_parts(&mut parts, state).await {
Ok(Extension(CachedEntry(value))) => Ok(Self(value)),
Err(_) => {
let req = Request::from_parts(parts, body);
let value = T::from_request(req, state).await?;
let value = T::from_request_parts(&mut parts, state).await?;
parts.extensions.insert(CachedEntry(value.clone()));
Ok(Self(value))
}
Expand Down
2 changes: 1 addition & 1 deletion axum-extra/src/extract/cookie/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ where
{
type Rejection = Infallible;

async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
Ok(Self::from_headers(&parts.headers))
}
}
Expand Down
2 changes: 1 addition & 1 deletion axum-extra/src/extract/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl<T> Deref for Form<T> {
impl<T, S, B> FromRequest<S, B> for Form<T>
where
T: DeserializeOwned,
B: HttpBody + Send,
B: HttpBody + Send + 'static,
B::Data: Send,
B::Error: Into<BoxError>,
S: Send + Sync,
Expand Down
2 changes: 1 addition & 1 deletion axum-extra/src/extract/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ where
{
type Rejection = QueryRejection;

async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
let query = parts.uri.query().unwrap_or_default();
let value = serde_html_form::from_str(query)
.map_err(FailedToDeserializeQueryString::__private_new)?;
Expand Down
6 changes: 3 additions & 3 deletions axum-extra/src/extract/with_rejection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<E, R> DerefMut for WithRejection<E, R> {
#[async_trait]
impl<B, E, R, S> FromRequest<S, B> for WithRejection<E, R>
where
B: Send,
B: Send + 'static,
S: Send + Sync,
E: FromRequest<S, B>,
R: From<E::Rejection> + IntoResponse,
Expand Down Expand Up @@ -161,8 +161,8 @@ mod tests {
type Rejection = ();

async fn from_request_parts(
parts: &mut Parts,
state: &S,
_parts: &mut Parts,
_state: &S,
) -> Result<Self, Self::Rejection> {
Err(())
}
Expand Down
Loading

0 comments on commit 69e7164

Please sign in to comment.