Replies: 1 comment
-
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Going by the names, one would be forgiven for thinking the difference between
axum::middleware::from_fn()
andaxum::middleware::from_fn_with_state()
is that one supports taking state (presumably at a performance cost?) and the other doesn't.I learned the hard way that no extractor is supported, so even for handlers that don't need state but use any extractor (e.g.
CookieJar
), you need to callmiddleware::from_fn_with_state(state.clone(), ...)
, needlessly cloning the state you're not going to access (and don't even take as a parameter).e.g. this doesn't compile:
but this will:
Is this intentional and is there perhaps a better name than
from_fn_with_state()
that conveys the actual difference?What's the best way to avoid cloning the app state here (can't just use
()
as the app state because the generic bounds won't line up any longer)?Beta Was this translation helpful? Give feedback.
All reactions