Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New FromRequest[Parts] trait cleanup #1288

Merged
merged 2 commits into from
Aug 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions axum-core/src/extract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@ mod tuple;

pub use self::from_ref::FromRef;

#[doc(hidden)]
pub mod private {
/// Private APIs

#[doc(hidden)]
mod private {
#[derive(Debug, Clone, Copy)]
pub enum Mut {}

#[doc(hidden)]
#[derive(Debug, Clone, Copy)]
pub enum Once {}
}
Expand Down
15 changes: 8 additions & 7 deletions axum-core/src/extract/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ where
}
}

mod private {
#[derive(Debug, Clone, Copy)]
pub enum TupleOnce {}
}

macro_rules! impl_from_request {
(
[$($ty:ident),*], $last:ident
Expand Down Expand Up @@ -53,10 +48,10 @@ macro_rules! impl_from_request {
// implementation of `FromRequest<S, B, Mut>` for `T: FromRequestParts<S>`.
#[async_trait]
#[allow(non_snake_case, unused_mut, unused_variables)]
impl<S, B, $($ty,)* $last> FromRequest<S, B, private::TupleOnce> for ($($ty,)* $last,)
impl<S, B, $($ty,)* $last> FromRequest<S, B> for ($($ty,)* $last,)
where
$( $ty: FromRequestParts<S> + Send, )*
$last: FromRequest<S, B, super::private::Once> + Send,
$last: FromRequest<S, B> + Send,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to write some docs about how to write generic extractors that wrap other extractors (that might or might not consume the request), this seems like pretty straight-forward advice: Implement both FromRequestParts and FromRequest, without any generic-ness over M in the latter case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Its on the todo list here

B: Send + 'static,
S: Send + Sync,
{
Expand Down Expand Up @@ -139,4 +134,10 @@ mod tests {
assert_from_request::<_, ((), ())>();
assert_from_request::<_, (Method, Bytes)>();
}

#[test]
fn nested_tuple() {
assert_from_request_parts::<(((Method,),),)>();
assert_from_request::<_, ((((Bytes,),),),)>();
}
}
2 changes: 1 addition & 1 deletion axum/src/handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ pub trait Handler<T, S = (), B = Body>: Clone + Send + Sized + 'static {
}
}

impl<F, Fut, Res, S, B> Handler<(axum_core::extract::private::Once,), S, B> for F
impl<F, Fut, Res, S, B> Handler<((),), S, B> for F
where
F: FnOnce() -> Fut + Clone + Send + 'static,
Fut: Future<Output = Res> + Send,
Expand Down