Closed johnpmitsch closed 1 month ago
you don't need State<>
, type has to be the same as you registered with App::state()
@fafhrd91 A key line was commented out, i just fixed it, the issue is more trying to appease the borrow checker, using req
twice, first to access the state, and then in ctx.call
// Error is here: Diagnostics:
// 1. cannot move out of `req` because it is borrowed
// move out of `req` occurs here [E0505]
let res = ctx.call(&self.service, req).await?;
if you wrap state in Arc, then just clone it
@fafhrd91 sorry, I think I'm missing the fix here, I made a reproducer here https://github.com/johnpmitsch/ntex_issue_repro/blob/main/src/main.rs - how am I supposed to clone the app data if I can't borrow req
?
app_state() returns Option<&T>, you need to do
let metrics_state = req.app_state::<Arc<metrics::MetricsState>>().cloned();
Thank you! .cloned()
is what I was missing, really appreciate the help 🙏🏻
Forgive me if I'm missing something obvious here, but I can't access state (
app_data
) in middleware, is there a way to do this? Here is what I'm trying: