Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use actix_web::http;
- use rusqlite::Connection;
- use std::sync::Arc;
- use std::sync::Mutex;
- mod api;
- mod db;
- fn main() {
- println!("Hello, world!");
- let db_connection = db::load_database("data.sqlite");
- start_server(db_connection);
- }
- fn start_server(db_connection: Connection) {
- let safe_db_connection = Arc::new(Mutex::new(db_connection));
- server::new( || App::new()
- .handler("/api/online", api::online)
- .route("/api/card/{id}", http::Method::GET, |req| api::card(req,safe_db_connection.clone())))
- .bind("127.0.0.1:8080").unwrap()
- .run();
- }
- // Definitions from other files
- pub fn load_database(file_name: &str) -> Connection {...}
- pub fn api::card(request: Path<i32>, db_connection: Arc<Mutex<Connection>>) -> impl Responder {...}
- // Exact error
- /*
- error[E0373]: closure may outlive the current function, but it borrows `safe_db_connection`, which is owned by the current function
- --> src/main.rs:25:18
- |
- 25 | server::new( || App::new()
- | ^^ may outlive borrowed value `safe_db_connection`
- 26 | .handler("/api/online", api::online)
- 27 | .route("/api/card/{id}", http::Method::GET, |req| api::card(req,safe_db_connection.clone())))
- | ------------------ `safe_db_connection` is borrowed here
- help: to force the closure to take ownership of `safe_db_connection` (and any other referenced variables), use the `move` keyword
- |
- 25 | server::new( move || App::new()
- | ^^^^^^^
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement