2

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?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
ddibiase
  • 1,412
  • 1
  • 20
  • 44
  • Please review how to create a [MCVE] and then [edit] your question to include it. We cannot tell what crates, types, traits, fields, etc. are present in the code. Try to produce something that reproduces your error on the [Rust Playground](https://play.rust-lang.org) or you can reproduce it in a brand new Cargo project. There are [Rust-specific MCVE tips](//stackoverflow.com/tags/rust/info) as well. – Shepmaster Jan 21 '19 at 01:33
  • Applying the duplicates, you'll probably need to use `server: HttpServer App>>` with the corresponding change inside the method, but since there's no MCVE, it's hard to state what exactly you'll need. – Shepmaster Jan 21 '19 at 01:42

0 Answers0