mod structs; use actix_web::{web, App, HttpServer}; use sqlx::mysql::{MySqlPool, MySqlPoolOptions}; #[derive(Clone)] struct AppState { pool: MySqlPool, } #[actix_web::main] async fn main() -> std::io::Result<()> { const DB_URL: &str = "mysql://root:@127.0.0.1:3306/balalaika"; let pool: MySqlPool = MySqlPoolOptions::new() .max_connections(10) .connect(DB_URL) .await .unwrap(); let app_state = AppState { pool }; HttpServer::new(move || { App::new() .app_data(web::Data::new(app_state.clone())) .route("/", web::get().to(root)) }) .bind(("127.0.0.1", 8000))? .run() .await } async fn root() -> String { String::from("Server is up and running") }