Rust actix-web框架

Tue 23 September 2025

Rust actix-web框架 目录 Github 官方文档 设置国内镜像 添加依赖 官方示例 下载依赖并编译运行 Github https://github.com/actix/actix-web 官方文档 https://actix.rs/docs/getting-started 设置国内镜像 cd ~/.cargo

创建config文件

vim config

添加如下镜像源

[source.crates-io] replace-with = 'rsproxy-sparse' [source.rsproxy] registry = "https://rsproxy.cn/crates.io-index" [source.rsproxy-sparse] registry = "sparse+https://rsproxy.cn/index/" [registries.rsproxy] index = "https://rsproxy.cn/crates.io-index" [net] git-fetch-with-cli = true 添加依赖 [dependencies] actix-web = "4" 官方示例 use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder};

[get("/")]

async fn hello() -> impl Responder { HttpResponse::Ok().body("Hello world!") }

[post("/echo")]

async fn echo(req_body: String) -> impl Responder { HttpResponse::Ok().body(req_body) }

async fn manual_hello() -> impl Responder { HttpResponse::Ok().body("Hey there!") }

[actix_web::main]

async fn main() -> std::io::Result<()> { HttpServer::new(|| { App::new() .service(hello) .service(echo) .route("/hey", web::get().to(manual_hello)) }) .bind(("127.0.0.1", 8080))? .run() .await } 下载依赖并编译运行 cargo run http://127.0.0.1:8080 http://127.0.0.1:8080/hey

Category: 编程rust


Rust cargo常用命令

Tue 23 September 2025

Rust cargo常用命令 目录 设置国内镜像 创建新项目 构建项目 运行项目 检查项目,但不构建可执行文件 运行项目的测试 发布项目 更新依 …

Category: 编程rust

Read More

Rust Druid桌面应用框架

Tue 23 September 2025

Rust Druid桌面应用框架 目录 Github 管方文档 简介 声明式 UI 数据绑定 高性能 可扩展性 跨平台 事件处理 生命周期管理 社区支持 设置国内镜像 添 …

Category: 编程rust

Read More

Rust安装及学习资料

Tue 23 September 2025

Rust安装及学习资料 目录 官网 包管理 Rust 程序设计语言 通过例子学 Rust 在线运行 安装rustup 升级Rust 卸载Rust 创建项目 官网 https://www.rust-lang.org/zh-CN/ 包管理 https://crates …

Category: 编程rust

Read More

减少rust编译后程序体积

Tue 23 September 2025

减少rust编译后程序体积

StrangenessWind IP属地: 上海 2021.01.05 19:41:20 字数 100 阅读 4,772 第一步: 编译release版本

cargo build --release 第二步: strip 命令

strip -s target/release/testGui 扩展 整优化等级 通过修 …

Category: 编程rust

Read More
Page 1 of 1