-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support
#[derive(FromRequest)]
on enums (#1009)
* Support `#[from_request(via(...))]` on enums * Check `#[from_request]` on variants * check for non enum/struct and clean up * changelog * changelog * remove needless feature * changelog ref
- Loading branch information
1 parent
a3a32f4
commit 852e548
Showing
14 changed files
with
215 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
axum-macros/tests/from_request/fail/enum_from_request_ident_in_variant.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use axum_macros::FromRequest; | ||
|
||
#[derive(FromRequest, Clone)] | ||
#[from_request(via(axum::Extension))] | ||
enum Extractor { | ||
Foo { | ||
#[from_request(via(axum::Extension))] | ||
foo: (), | ||
} | ||
} | ||
|
||
fn main() {} |
5 changes: 5 additions & 0 deletions
5
axum-macros/tests/from_request/fail/enum_from_request_ident_in_variant.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: `#[from_request(via(...))]` cannot be used inside variants | ||
--> tests/from_request/fail/enum_from_request_ident_in_variant.rs:7:24 | ||
| | ||
7 | #[from_request(via(axum::Extension))] | ||
| ^^^ |
10 changes: 10 additions & 0 deletions
10
axum-macros/tests/from_request/fail/enum_from_request_on_variant.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use axum_macros::FromRequest; | ||
|
||
#[derive(FromRequest, Clone)] | ||
#[from_request(via(axum::Extension))] | ||
enum Extractor { | ||
#[from_request(via(axum::Extension))] | ||
Foo, | ||
} | ||
|
||
fn main() {} |
5 changes: 5 additions & 0 deletions
5
axum-macros/tests/from_request/fail/enum_from_request_on_variant.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: `#[from_request(via(...))]` cannot be used on variants | ||
--> tests/from_request/fail/enum_from_request_on_variant.rs:6:20 | ||
| | ||
6 | #[from_request(via(axum::Extension))] | ||
| ^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use axum_macros::FromRequest; | ||
|
||
#[derive(FromRequest, Clone)] | ||
enum Extractor {} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
error: missing `#[from_request(via(...))]` | ||
--> tests/from_request/fail/enum_no_via.rs:3:10 | ||
| | ||
3 | #[derive(FromRequest, Clone)] | ||
| ^^^^^^^^^^^ | ||
| | ||
= note: this error originates in the derive macro `FromRequest` (in Nightly builds, run with -Z macro-backtrace for more info) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use axum_macros::FromRequest; | ||
|
||
#[derive(FromRequest, Clone)] | ||
#[from_request(rejection_derive(!Error))] | ||
enum Extractor {} | ||
|
||
fn main() {} |
5 changes: 5 additions & 0 deletions
5
axum-macros/tests/from_request/fail/enum_rejection_derive.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: cannot use `rejection_derive` on enums | ||
--> tests/from_request/fail/enum_rejection_derive.rs:4:16 | ||
| | ||
4 | #[from_request(rejection_derive(!Error))] | ||
| ^^^^^^^^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use axum_macros::FromRequest; | ||
|
||
#[derive(FromRequest)] | ||
union Extractor {} | ||
|
||
fn main() {} |
11 changes: 11 additions & 0 deletions
11
axum-macros/tests/from_request/fail/not_enum_or_struct.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error: expected `struct` or `enum` | ||
--> tests/from_request/fail/not_enum_or_struct.rs:4:1 | ||
| | ||
4 | union Extractor {} | ||
| ^^^^^^^^^^^^^^^^^^ | ||
|
||
error: unions cannot have zero fields | ||
--> tests/from_request/fail/not_enum_or_struct.rs:4:1 | ||
| | ||
4 | union Extractor {} | ||
| ^^^^^^^^^^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use axum::{body::Body, routing::get, Extension, Router}; | ||
use axum_macros::FromRequest; | ||
|
||
#[derive(FromRequest, Clone)] | ||
#[from_request(via(Extension))] | ||
enum Extractor {} | ||
|
||
async fn foo(_: Extractor) {} | ||
|
||
fn main() { | ||
Router::<Body>::new().route("/", get(foo)); | ||
} |