Rust編寫Shop管理系統
Actix Web 是一個功能強大、實用且速度極快的 Rust Web 框架。編寫Shop管理系統
HelloKeny
首先是先編寫最簡單的例子,類似hello World可以檢查環境
Actix Web 是一個功能強大、實用且速度極快的 Rust Web 框架。
命令
cargo new hellokenycd hellokeny
項目目錄
目錄包括src目錄,main.rs以及 Cargo.toml基本文件
main.js
fn main() {println!("HelloKeny!");
}
運行結果
actix_web簡單例子
1.修改main.js
2.cargo add actix_web
main.js代碼
use actix_web::{get, web, App, HttpServer, Responder};#[get("/hello/{name}")]
async fn greet(name: web::Path<String>) -> impl Responder {format!("Hello {}!", name)
}#[actix_web::main] // or #[tokio::main]
async fn main() -> std::io::Result<()> {HttpServer::new(|| {App::new().service(greet)}).bind(("127.0.0.1", 8080))?.run().await
}
編譯
cargo build --release,編譯后成功建立目錄
運行結果
后臺運行
瀏覽器
Cargo.toml的文件內容
[package]
name = "hellokeny"
version = "0.1.0"
edition = "2024"[dependencies]
actix-web = "4.11.0"