* Improve `debug_handler` to use the correct span for specific bounds
This results in better localised error messages, as they now point
directly to the corresponding argument instead of to the macro itself.
* Improve some error messages behind a `nightly-error-messages` feature
flag
This uses the nightly only `rustc_on_unimplemented` attribute to improve
some error messages when users try to use invalid handler functions.
This should be seen as prove of concept, not as full solution for all
potential error cases.
The underlying feature is currently marked as permanently unstable, but
I'm working on getting this specific attribute (or an attribute with
different name, similar functionality) ready to work on a stable compiler.
* Apply suggestions from code review
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
* Enable the `nightly-error-messages` feature unconditionally for nightly compilers
* Use a nightly compiler to run the axum-marcos compile fail tests
* update to newer nightly
* Run axum-macros tests on nightly
* tweak compile error hints a bit
* more tweaks
* update test
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
Previously
```rust
handler.layer(RequestBodyLimitLayer::new(...)).with_state(...)
```
didn't work because we required the same request body all the way
through.
* Change `FailedToDeserializeQueryString` rejection for `Form`
Its now called `FailedToDeserializeForm`.
* changelog
* Make dedicate rejection type for axum-extra's `Form`
* update trybuild test
* Make dedicate rejection type for axum-extra's `Query`
* Add RawForm extractor
* Change RawForm(String) to RawForm(Option<String>)
* Fix tests
* Use Bytes instead of Option<String> and add tests
* Add test for empty body
* Update CHANGELOG
* small docs tweaks
* changelog nit
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
* add `#[derive(FromRef)]`
* tests
* don't support skipping fields
probably wouldn't work at all since the whole state likely needs `Clone`
* UI tests
* changelog
* changelog link
* revert hello-world example, used for testing
* Re-export `#[derive(FromRef)]`
* Don't need to return `Result`
* use `collect` instead of quoting the iterator
* Mention it in axum's changelog
* Add a dedicated error message for state type inference issues
* Generate valid code even if state type can't be inferred
* Also error on state type inference for debug_handler
* Support `State` with `#[derive(FromRequest[Parts])]`
Fixes https://github.com/tokio-rs/axum/issues/1314
This makes it possible to extract things via `State` in
`#[derive(FromRequet)]`:
```rust
struct Foo {
state: State<AppState>,
}
```
The state can also be inferred in a lot of cases so you only need to
write:
```rust
struct Foo {
// since we're using `State<AppState>` we know the state has to be
// `AppState`
state: State<AppState>,
}
```
Same for
```rust
struct Foo {
#[from_request(via(State))]
state: AppState,
}
```
And
```rust
struct AppState {}
```
I think I've covered all the edge cases but there are (unsurprisingly) a
few.
* make sure things can be combined with other extractors
* main functions in ui tests don't need to be async
* Add test for multiple identicaly state types
* Add failing test for multiple states
* Refactor proc-macro attribute parsing
* Remove `#[allow(warnings)]` which was accidentally committed
* Change span for "cannot use `rejection` without `via`" error for enums
* fix test
* Add missing leading double colon
* Separate handling of last element in FromRequest derive
* FromRequestParts derive
* fix it and add lots of tests
* docs
* changelog
* Update axum-macros/src/lib.rs
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
* Only allow last extractor to mutate the request
* Change `FromRequest` and add `FromRequestParts` trait (#1275)
* Add `Once`/`Mut` type parameter for `FromRequest` and `RequestParts`
* 🪄
* split traits
* `FromRequest` for tuples
* Remove `BodyAlreadyExtracted`
* don't need fully qualified path
* don't export `Once` and `Mut`
* remove temp tests
* depend on axum again
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
* Port `Handler` and most extractors (#1277)
* Port `Handler` and most extractors
* Put `M` inside `Handler` impls, not trait itself
* comment out tuples for now
* fix lints
* Reorder arguments to `Handler` (#1281)
I think `Request<B>, Arc<S>` is better since its consistent with
`FromRequest` and `FromRequestParts`.
* Port most things in axum-extra (#1282)
* Port `#[derive(TypedPath)]` and `#[debug_handler]` (#1283)
* port #[derive(TypedPath)]
* wip: #[debug_handler]
* fix #[debug_handler]
* don't need itertools
* also require `Send`
* update expected error
* support fully qualified `self`
* Implement FromRequest[Parts] for tuples (#1286)
* Port docs for axum and axum-core (#1285)
* Port axum-extra (#1287)
* Port axum-extra
* Update axum-core/Cargo.toml
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
* remove `impl FromRequest for Either*`
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
* New FromRequest[Parts] trait cleanup (#1288)
* Make private module truly private again
* Simplify tuple FromRequest implementation
* Port `#[derive(FromRequest)]` (#1289)
* fix tests
* fix docs
* revert examples
* fix docs link
* fix intra docs links
* Port examples (#1291)
* Document wrapping other extractors (#1292)
* axum-extra doesn't need to depend on axum-core (#1294)
Missed this in https://github.com/tokio-rs/axum/pull/1287
* Add `FromRequest` changes to changelogs (#1293)
* Update changelog
* Remove default type for `S` in `Handler`
* Clarify which types have default types for `S`
* Apply suggestions from code review
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
* remove unused import
* Rename `Mut` and `Once` (#1296)
* fix trybuild expected output
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>