面试题答案
一键面试use actix_web::{get, web, App, HttpResponse, HttpServer, Responder};
// 根路由处理函数
#[get("/")]
async fn index() -> impl Responder {
HttpResponse::Ok().body("Hello, World!")
}
// /about路由处理函数
#[get("/about")]
async fn about() -> impl Responder {
HttpResponse::Ok().body("This is a simple web server built with actix - web in Rust.")
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.service(index)
.service(about)
})
.bind("127.0.0.1:8080")?
.run()
.await
}