I'm playing around with actix-web, trying out a few things. The issue I've bumped into was writing two wrapper functions using extensions_mut
and extensions
on HttpMessage
(for ServiceRequest
).
I think that the following will put an u32
in a requests extensions:
.wrap_fn(|req, srv| {
req.extensions_mut().insert(42_u32);
srv.call(req)
})
However, when I later (i.e. below) try to get it out again with this code:
.wrap_fn(|req, srv| {
{
let exts = req.extensions();
let val = exts.get::<u32>();
println!("found: {:?}", val);
}
srv.call(req)
I get a None
.
Have I misunderstood the API and what it offers, or is it just a silly mistake in my code?