-
-
Save rust-play/2312d148dc93687e22c39ee8f33693c3 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use actix_web::{get, web, App, HttpServer, Responder}; | |
use dashmap::DashMap; | |
#[get("/")] | |
async fn index(state_data: web::Data<AppState>) -> impl Responder { | |
"Hello World!" | |
} | |
#[get("/test")] | |
async fn test(state_data: web::Data<AppState>) -> impl Responder { | |
let dashMap = &state_data.dashMap; | |
// for k in dashMap { | |
// println!("{:#?}", (k)); | |
// } | |
"Hello World!" | |
} | |
pub struct AppState { | |
pub dashMap: DashMap<String, String>, | |
} | |
#[actix_web::main] | |
async fn main() -> std::io::Result<()> { | |
let dm: DashMap<String, String> = DashMap::new(); | |
dm.insert("ok".to_string(), "ok".to_string()); | |
let state_data = web::Data::new(AppState { dashMap: dm }); | |
HttpServer::new(move || { | |
App::new() | |
.service(index) | |
.service(test) | |
.app_data(state_data.clone()) | |
}) | |
.bind("127.0.0.1:8081")? | |
.run() | |
.await | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment