I'm trying to build something based on examples in the actix-web repo.
This code works fine
use actix_web::{
http,
middleware::Logger,
server, App, HttpRequest, Json, Result,
};
#[derive(Clone)]
struct State {
val: u32,
}
fn data(input: Json<input::Input>, /* req: &HttpRequest<State> */) -> Result<String> {
let mut v: u32 = 0;
// let v = req.state().val;
Ok(format!("got data {}", v))
}
fn main() {
server::new(|| {
App::with_state(State {
val: 10
})
.middleware(Logger::default())
.resource("/data", |r| r.method(http::Method::POST).with(data))
})
.bind("127.0.0.1:8088")
.unwrap()
.run();
}
mod input;
but if I uncomment the state args and usage in fn data
:
fn data(input: Json<input::Input>, req: &HttpRequest<State>) -> Result<String> {
let mut v: u32 = 0;
let v = req.state().val;
Ok(format!("got data {}", v))
}
I get a gnarly error on the .with()
in the routing that I can't budge.
the trait bound
for<'r> fn(actix_web::json::Json<input::Input>, &'r actix_web::httprequest::HttpRequest<State>) -> std::result::Result<std::string::String, actix_web::error::Error> {data}: actix_web::with::WithFactory<_, State, _>
is not satisfiedthe trait
actix_web::with::WithFactory<_, State, _>
is not implemented forfor<'r> fn(actix_web::json::Json<input::Input>, &'r actix_web::httprequest::HttpRequest<State>) -> std::result::Result<std::string::String, actix_web::error::Error> {data}
Clues very welcome. The examples are somewhat inconsistent with eachother and there seem to so so many different ways of doing things, but none are coming together.