Commit graph

73 commits

Author SHA1 Message Date
Zheng Li
aac67f1152
Update axum-macros/src/from_request.rs
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2024-09-28 18:25:29 +08:00
Zheng Li
e305bbbad1
Update axum-macros/src/from_request.rs
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2024-09-28 18:25:19 +08:00
Zheng Li
0e0ad984c7
Update axum-macros/src/from_request.rs
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2024-09-28 18:25:13 +08:00
Zheng Li
b46976f661
Update axum-macros/src/from_request.rs
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2024-09-28 18:25:06 +08:00
Zheng Li
8b76b09d99
Update axum-macros/src/from_request.rs
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2024-09-28 18:24:48 +08:00
Zheng Li
fc470ce06b
Update lib.rs 2024-09-23 02:22:22 +08:00
Jonas Platte
361632f9ae
Merge branch 'main' into main 2024-09-20 23:19:20 +02:00
tiaoxizhan
680cdcba7c
chore: Add missing symbol (#2909)
Signed-off-by: tiaoxizhan <tiaoxizhan@outlook.com>
2024-09-12 19:44:44 +02:00
Benno van den Berg
50274725cb
Resolve clippies (#2843) 2024-07-24 00:07:25 +02:00
AlphaKeks
74eac39e06
Fix clippy warning on FromRef derive macro (#2827) 2024-07-09 23:08:59 +02:00
Chris Pick
035c8a36b5
Fix a few typos in docs and comments (#2808) 2024-06-27 08:45:57 +02:00
Yann Simon
df612fdc72
Add #[debug_middleware] (#2725)
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2024-05-02 17:27:12 -04:00
David Mládek
66b3b3df55
Document usage of concrete state in FromRequest macro (#2550) (#2581) 2024-02-11 12:12:03 +01:00
Nick Price
934b1aac06
Grammar: Fix "it's" vs "its" in several places (#2518) 2024-01-15 21:48:11 +01:00
Sleep_AllDay
d2cea5cdbd
Improve debug_handler on tuple response types (#2201)
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2023-12-30 21:48:35 +00:00
lz1998
a160f98ac2 remove async_trait 2023-12-30 01:09:36 +08:00
Justin Sexton
f98bc1186a
Updated doc link versions to use more explicit 0.7 version. (#2379) 2023-11-29 09:31:17 +00:00
Justin Sexton
57c59170c0
Updated doc link versions from 0.6.x to 0.7. (#2378) 2023-11-29 08:44:32 +00:00
Yuri Astrakhan
17993c5717
A few clippy inspired changes (#2233) 2023-09-29 07:28:57 +00:00
Georg Semmler
2f6200dfbd
Use the diagnostic namespace (#2246) 2023-09-29 09:25:26 +02:00
nabbisen
70171980cc
fix typo in axum-macros README: according to Cargo.toml msrv is 1.60 (#2204) 2023-09-11 12:03:50 +00:00
Alexander Jackson
68696b09b1
Allow unreachable code in #[debug_handler] (#2014)
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2023-06-22 21:51:52 +00:00
David Pedersen
877e3fe4de Move TypedHeader to axum-extra (#1850)
Co-authored-by: Michael Scofield <mscofield0@tutanota.com>
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2023-04-21 17:45:31 +02:00
David Pedersen
c97967252d Add serve function and remove Server re-export (#1868) 2023-04-21 17:45:31 +02:00
David Pedersen
6703f8634c Remove B type param: Follow ups (#1789)
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
Co-authored-by: Michael Scofield <mscofield0@tutanota.com>
2023-04-21 17:45:31 +02:00
David Pedersen
4e4c29175f Remove B type param (#1751)
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
Co-authored-by: Michael Scofield <mscofield0@tutanota.com>
2023-04-21 17:45:31 +02:00
David Pedersen
39bb28130d
Enable println warning (#1929) 2023-04-14 22:26:56 +02:00
David Pedersen
cfb5df7050
Give better error if generics are used with #[derive(FromRef)] (#1874) 2023-03-22 14:48:27 +01:00
David Pedersen
8e1eb8979f
Update to syn 2 (#1862) 2023-03-18 19:23:27 +00:00
Jonas Platte
a26ddd1063
Improve debug_handler message for generic request-consuming extractors (#1826)
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2023-03-10 08:51:03 +00:00
A-Walrus
1327a598ce
Hide debug_handler generated functions from docs (#1825) 2023-03-07 10:20:50 +00:00
David Pedersen
6075be60ed
Wording tweak in #[debug_handler] docs (#1807) 2023-03-03 12:38:26 +01:00
Jesper Josefsson
67befbca52
Document the fact that debug_handler doesn't work within impl blocks (#1800)
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
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
Jules Guesnon
67422bb1c2
Allow clone_on_copy for FromRef (#1749) 2023-02-12 12:16:53 +01:00
Jonas Platte
bdfaedb344 Use call-site span for future Send check in debug_handler 2023-01-30 21:47:57 +01: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
Alexander Jackson
b6c282a2b7
Fix warnings for cloning references in generated code (#1676) 2023-01-05 11:50:02 +01: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
Georg Semmler
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 <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>
2022-11-19 12:45:03 +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
Jonas Platte
c3fa0b2a3e
Fix unused variable warning when developing using a nightly toolchain (#1520) 2022-11-10 12:41:16 +01:00
Jonas Platte
36f24990c8 Fix clippy lints 2022-11-05 11:33:27 +01: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
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
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
David Pedersen
2abda4de88
Port other proc-macros to new attribute parsing (#1372) 2022-09-12 21:26:10 +02:00