Commit Graph
82 Commits
Author SHA1 Message Date
Jesper JosefssonandDavid Pedersen 67befbca52 Document the fact that debug_handler doesn't work within impl blocks (#1800)
Co-authored-by: David Pedersen <[email protected]>
2023-03-03 09:57:50 +01:00
David Pedersen 416a0568d3 Add special handling of FromRequest extractors not being the last arg (#1797) 2023-03-03 09:44:10 +01:00
Spencer Bartholomew 6067223fcc update tokio dep to fix potential security vulnerability (#1787) 2023-02-27 18:40:03 +01:00
David Pedersen 08bac36519 Release axum and axum-extra (#1788) 2023-02-27 09:41:11 +01:00
David Pedersen cd86f7ec7a Use 422 Unprocessable Entity for Form deserialization errors, except GET and HEAD requests (#1683) 2023-02-17 09:59:02 +01:00
David Pedersen e6ff0281ae Try cargo public-api-crates on CI (#1761) 2023-02-16 22:41:41 +01:00
David Pedersen c18ff9dd63 Release axum, axum-extra, and axum-macros (#1750) 2023-02-12 12:40:42 +01:00
Jules Guesnon 67422bb1c2 Allow clone_on_copy for FromRef (#1749) 2023-02-12 12:16:53 +01:00
David Pedersen 0ecf5eeb19 Support passing MethodRouter to Router::fallback (#1730) 2023-02-11 23:11:55 +01:00
David Pedersen 93ecabf449 Release axum and axum-macros (#1743) 2023-02-11 22:32:16 +01:00
Jonas Platte 19596584da Update trybuild output 2023-01-30 21:47:57 +01:00
Jonas Platte bdfaedb344 Use call-site span for future Send check in debug_handler 2023-01-30 21:47:57 +01:00
David Pedersen 4a5dc4391c Release axum and axum-macros (#1721) 2023-01-24 13:31:33 +01:00
David Pedersen 5b07296001 Add RawPathParams (#1713) 2023-01-20 20:37:01 +00:00
Jonas Platte 7ecf8bd6cf Use implicit format-args captures where applicable (#1709) 2023-01-20 12:04:49 +01:00
David Pedersen 1be25d9496 Add internal macro to make tests of nest easier to write (#1694) 2023-01-14 14:12:01 +00:00
valkyrie_pilotandDavid Pedersen e4c6d76bca Implement IntoResponse for [u8; N] and &'static [u8; N] (#1690)
Co-authored-by: David Pedersen <[email protected]>
2023-01-13 09:12:51 +00:00
David Pedersen e3aaeb3cb7 Release axum, axum-core, and axum-macros (#1688) 2023-01-09 13:54:49 +01:00
Alexander Jackson b6c282a2b7 Fix warnings for cloning references in generated code (#1676) 2023-01-05 11:50:02 +01:00
David PedersenandJonas Platte 1b6780cf6c axum 0.6 and friends 🎉 (#1570)
* changelog

* bump versions

* reorder changelogs a bit

* Apply suggestions from code review

Co-authored-by: Jonas Platte <[email protected]>

* Expand fallback inheritance

* Reword tsr

* Mention `parse-body-based-on-content-type` example

Co-authored-by: Jonas Platte <[email protected]>
2022-11-25 12:29:58 +00:00
David Pedersen 0b26411f39 Change Router::with_state and impl Service for Router<()> (#1552)
* Implement `Service` for `Router<(), B>`

* wip

* wip

* fix some tests

* fix examples

* fix doc tests

* clean up docs

* changelog

* fix

* also call `with_state` when converting `MethodRouter` into a `MakeService`

* suggestions from review
2022-11-24 14:43:10 +00:00
Jonas Platte 8d2fb3618e Remove unused imports from doctest (#1551) 2022-11-20 01:41:50 +01:00
David Pedersen 99c0224a7c axum-extra 0.4.0-rc.3 (#1545)
* axum-extra 0.4.0-rc.3

Needs a new release because it uses the old state inheritance whic is
removed in the latest rc.

* fix
2022-11-19 13:02:11 +01:00
d5de3bc7e3 Improve compile errors for unimplemented traits (#1436)
* 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 <[email protected]>

* 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 <[email protected]>
Co-authored-by: David Pedersen <[email protected]>
2022-11-19 12:45:03 +01:00
David Pedersen 878ae73e6d New release candidates (#1541) 2022-11-18 17:29:47 +01:00
David Pedersen 7d58d49817 Add #[from_ref(skip)] (#1537)
For skipping individual fields.
2022-11-18 12:05:10 +01:00
David Pedersen 64960bb19c Type safe state inheritance (#1532)
* Make state type safe

* fix examples

* remove unnecessary `#[track_caller]`s

* Router::into_service -> Router::with_state

* fixup docs

* macro docs

* add missing docs

* fix examples

* format

* changelog

* Update trybuild tests

* Make sure fallbacks are still inherited for opaque services (#1540)

* Document nesting routers with different state

* fix leftover conflicts
2022-11-18 11:02:58 +00:00
David Pedersen 2e8a7e51a1 Fix Handler::with_state not working if request body was changed via layer (#1536)
Previously

```rust
handler.layer(RequestBodyLimitLayer::new(...)).with_state(...)
```

didn't work because we required the same request body all the way
through.
2022-11-18 11:00:52 +01:00
Jonas Platte c3fa0b2a3e Fix unused variable warning when developing using a nightly toolchain (#1520) 2022-11-10 12:41:16 +01:00
David PedersenandJonas Platte e39d053d2f New release candidates (#1514)
* New release candidates

* Update axum/Cargo.toml

Co-authored-by: Jonas Platte <[email protected]>

Co-authored-by: Jonas Platte <[email protected]>
2022-11-09 09:01:47 +01:00
David Pedersen e0ef641e5f Rework Form and Query rejections (#1496)
* 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`
2022-11-08 20:31:06 +00:00
Jonas Platte 36f24990c8 Fix clippy lints 2022-11-05 11:33:27 +01:00
David Pedersen a27bd2c6a2 Update trybuild tests for Rust 1.65.0 (#1509) 2022-11-04 09:07:57 +01:00
Marek KuskowskiandDavid Pedersen bc8a507f58 Add RawForm extractor (#1487)
* 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 <[email protected]>
2022-10-20 18:03:13 +00:00
David Pedersen 9c0a89cd09 Add #[derive(FromRef)] (#1430)
* 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
2022-10-10 18:40:14 +00:00
David Pedersen f9dc96fdce Don't internally Arc the state (#1460) 2022-10-09 20:55:28 +00:00
Jonas Platte 7cbacd1433 Improve the error message for state type inference failure in FromRequest(Parts) derive macro (#1432)
* 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
2022-10-09 20:25:05 +02:00
Marek KuskowskiandDavid Pedersen 896ffc5fba Remove ContentLengthLimit (#1400)
* feat: remove ContentLengthLimit

* feat: remove ContentLengthLimit rejections

* fix: update multipart docs

* fix: typo

* feat: add wip extractor code

* feat: revert "feat: add wip extractor code"

* fix: update Multipart docs

* fix: update examples

* fix: missing import in an example

* fix: broken import yet again

* fix: disable default body limit for example

* fix: key value store example

* fix: update expected debug_handler output

* chore: update CHANGELOG

* Update axum/CHANGELOG.md

Co-authored-by: David Pedersen <[email protected]>
2022-09-24 11:29:53 +00:00
David Pedersen c3f3db79ec Support State with #[derive(FromRequest[Parts])] (#1391)
* 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
2022-09-23 23:50:50 +02:00
Jonas Platte 4c846488c2 Update expected stderr of trybuild test (#1402) 2022-09-22 18:36:31 +02:00
David Pedersen 2abda4de88 Port other proc-macros to new attribute parsing (#1372) 2022-09-12 21:26:10 +02:00
David Pedersen 8da69a98fc Refactor proc-macro attribute parsing (#1369)
* 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
2022-09-12 20:10:58 +02:00
David PedersenandJonas Platte 54d8439e35 Ship rc.2 (#1363)
* rc.2

* don't bump version of axum-macros

* fix

* Update axum/Cargo.toml

Co-authored-by: Jonas Platte <[email protected]>

* undo release of axum-extra

* fix

Co-authored-by: Jonas Platte <[email protected]>
2022-09-11 16:42:04 +02:00
David Pedersen b315b60bca Bump version of all crates (#1310)
* Bump version of all crates

* use the right versions inside the workspace
2022-08-23 22:57:13 +02:00
Jonas PlatteandDavid Pedersen 7705ef6661 Add #[derive(FromRequestParts)] (#1305)
* 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 <[email protected]>

Co-authored-by: David Pedersen <[email protected]>
2022-08-23 19:14:02 +00:00
David Pedersen bb05dea672 Generate correct bound for non-last extractor in #[debug_handler] (#1299)
* Support running a single UI test

* Generate correct `FromRequestParts` bound

* don't depend on itertools
2022-08-22 15:34:17 +02:00
David PedersenandJonas Platte be624306f4 Only allow last extractor to mutate the request (#1272)
* 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 <[email protected]>

* 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 <[email protected]>

* remove `impl FromRequest for Either*`

Co-authored-by: Jonas Platte <[email protected]>

* 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 <[email protected]>

Co-authored-by: Jonas Platte <[email protected]>

* remove unused import

* Rename `Mut` and `Once` (#1296)

* fix trybuild expected output

Co-authored-by: Jonas Platte <[email protected]>
2022-08-22 12:23:20 +02:00
David Pedersen 568394a28e Support changing state type in #[debug_handler] (#1271)
* support setting body type for #[debug_handler]

* Use lookahead1 to give better errors and detect duplicate arguments

* fix docs link
2022-08-18 11:41:14 +02:00
David Pedersen e7f1c88cd4 Always store state in an Arc (#1270)
* Add extension and state benchmarks

* wip

* Arc the state everywhere

* don't require `S: Clone`

* fix example
2022-08-17 20:08:24 +00:00
423308de3c Add type safe state extractor (#1155)
* begin threading the state through

* Pass state to extractors

* make state extractor work

* make sure nesting with different states work

* impl Service for MethodRouter<()>

* Fix some of axum-macro's tests

* Implement more traits for `State`

* Update examples to use `State`

* consistent naming of request body param

* swap type params

* Default the state param to ()

* fix docs references

* Docs and handler state refactoring

* docs clean ups

* more consistent naming

* when does MethodRouter implement Service?

* add missing docs

* use `Router`'s default state type param

* changelog

* don't use default type param for FromRequest and RequestParts

probably safer for library authors so you don't accidentally forget

* fix examples

* minor docs tweaks

* clarify how to convert handlers into services

* group methods in one impl block

* make sure merged `MethodRouter`s can access state

* fix docs link

* test merge with same state type

* Document how to access state from middleware

* Port cookie extractors to use state to extract keys (#1250)

* Updates ECOSYSTEM with a new sample project (#1252)

* Avoid unhelpful compiler suggestion (#1251)

* fix docs typo

* document how library authors should access state

* Add `RequestParts::with_state`

* fix example

* apply suggestions from review

* add relevant changes to axum-extra and axum-core changelogs

* Add `route_service_with_tsr`

* fix trybuild expectations

* make sure `SpaRouter` works with routers that have state

* Change order of type params on FromRequest and RequestParts

* reverse order of `RequestParts::with_state` args to match type params

* Add `FromRef` trait (#1268)

* Add `FromRef` trait

* Remove unnecessary type params

* format

* fix docs link

* format examples

* Avoid unnecessary `MethodRouter`

* apply suggestions from review

Co-authored-by: Dani Pardo <[email protected]>
Co-authored-by: Jonas Platte <[email protected]>
2022-08-17 15:13:31 +00:00