Issue Title: Borrowed data escapes outside of associated function in Server::run
Description
This issue reports a compilation error encountered in the Server::run
function located in src/server/server.rs
. The error message indicates that a borrowed reference (vars
) is being used in a closure where its lifetime doesn't match the requirements.
Error Message:
error[E0521]: borrowed data escapes outside of associated function
--> src/server/server.rs:40:7
|
22 | pub async fn run(vars: &Config, auth: bool) {
| ---- - let's call the lifetime of this reference `'1`
| | | `vars` is a reference that is only valid in the associated function body
...
40 | / App::new()
41 | | .wrap(HttpAuthentication::basic(move |req, creds| {
42 | | async move {
43 | | Auth::auth(auth,vars.clone(), req, creds).await
44 | | }
45 | | }))
| | ^
| | |
| |_________`vars` escapes the associated function body here
| argument requires that `'1` must outlive `'static`
Code
pub struct Server;
impl Server {
#[actix_web::main]
pub async fn run(vars: &Config, auth: bool) {
let socket_addr: SocketAddr = vars.bind.parse().expect("Failed to parse Socket Address");
info!("[SERVER] running on {}.", socket_addr);
let governor_conf = GovernorConfigBuilder::default()
.per_second(1)
.burst_size(1)
.finish()
.unwrap_or_else( || {
error!("{}", ServerError::RateLimitConfigError.to_string());
process::exit(1);
});
if !auth {
warn!("[SERVER] Authentication is not enabled! Your server is vulnerable to attacks. Use --auth to enable authentication.");
}
HttpServer::new(move || {
App::new()
.wrap(HttpAuthentication::basic(move |req, creds| {
async move {
Auth::auth(auth,vars.clone(), req, creds).await
}
}))
.wrap(Governor::new(&governor_conf))
.route("/", web::post().to(endpoint))
})
.workers(vars.workers)
.max_connections(vars.max_connections)
.bind(socket_addr)
.unwrap_or_else(|err| {
error!("{}", ServerError::BindError(err.to_string()).to_string());
process::exit(1);
})
.run()
.await
.unwrap();
}
}
Additional Information
- Programming language: Rust
- Steps to reproduce (if applicable): Describe the steps to trigger the error.
Labels
- bug
- lifetime
Thanks for helping!