Skip to content

Commit 280d16a

Browse files
Lachstecmladedav
andauthored
Improve docs regarding state and extensions (#2991)
Co-authored-by: David Mládek <david.mladek.cz@gmail.com>
1 parent 7281984 commit 280d16a

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

axum/src/docs/routing/with_state.md

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
Provide the state for the router.
1+
Provide the state for the router. State passed to this method is global and will be used
2+
for all requests this router receives. That means it is not suitable for holding state derived from a request, such as authorization data extracted in a middleware. Use [`Extension`] instead for such data.
23

34
```rust
45
use axum::{Router, routing::get, extract::State};
@@ -94,13 +95,6 @@ axum::serve(listener, routes).await.unwrap();
9495
# };
9596
```
9697

97-
# State is global within the router
98-
99-
The state passed to this method will be used for all requests this router
100-
receives. That means it is not suitable for holding state derived from a
101-
request, such as authorization data extracted in a middleware. Use [`Extension`]
102-
instead for such data.
103-
10498
# What `S` in `Router<S>` means
10599

106100
`Router<S>` means a router that is _missing_ a state of type `S` to be able to

axum/src/extract/state.rs

+4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ use std::{
1010
/// See ["Accessing state in middleware"][state-from-middleware] for how to
1111
/// access state in middleware.
1212
///
13+
/// State is global and used in every request a router with state receives.
14+
/// For accessing data derived from requests, such as authorization data, see [`Extension`].
15+
///
1316
/// [state-from-middleware]: crate::middleware#accessing-state-in-middleware
17+
/// [`Extension`]: crate::Extension
1418
///
1519
/// # With `Router`
1620
///

0 commit comments

Comments
 (0)