當(dāng)前位置:首頁 > IT技術(shù) > 其他 > 正文

【Axum】hello world
2022-04-29 14:02:33

環(huán)境

  • Time 2022-01-16
  • Rust 1.58.0
  • Axum 0.4.4

概念

參考:https://github.com/tokio-rs/axum/blob/main/examples/hello-world/src/main.rs

示例

main.rs

use axum::{routing::get, Router};
use std::net::SocketAddr;

#[tokio::main]
async fn main() {
    let app = Router::new().route("/", get(|| async { "hello world" }));

    let addr = SocketAddr::from(([127, 0, 0, 1], 4444));
    println!("listening on {addr}");
    axum::Server::bind(&addr)
        .serve(app.into_make_service())
        .await
        .unwrap();
}

總結(jié)

使用 axum 啟動(dòng)了一個(gè)服務(wù)器,訪問時(shí)返回 hello world。

附錄

本文摘自 :https://www.cnblogs.com/

開通會(huì)員,享受整站包年服務(wù)立即開通 >