Rust编写Shop管理系统
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"