I'm having trouble (as a newbie) getting my application to compile. This is likely the most obvious detail but I'm struggling with comprehending what's happening.
I'm writing a wrapper struct for the Actix Web server library. My struct is defined as such:
struct CustomServer {
connections: IncomingRequets,
server: HttpServer<App, fn() -> App>,
address: String,
port: i32,
}
I'm attempting to create the struct and return it via a function:
let address: Handle<JsString> = cx.argument::<JsString>(0)?;
let port: Handle<JsNumber> = cx.argument::<JsNumber>(1)?;
let server = server::new(|| {
App::new()
.middleware(middleware::Logger::default())
.default_resource(|r| r.f(index))
});
// Export the server struct
CustomServer {
address: address.value(),
port: port.value() as i32,
server: server,
connections: IncomingRequets {
requests: HashMap::new(),
},
}
expected fn pointer, found closure
. I do understand that this is likely due to a missing piece in my understanding of how concrete structs and types are declared. I also understand that I'm passing in a closure as opposed to a function.
So my thought process is: a) how can I declare a closure as part of the HttpServer
parameters or b) can I declare the function within the struct and return it as a factory/generator that returns the app?