🔮
Rust学习笔记
  • 介绍
  • Rust入门
    • 安装使用
    • Cargo初用
    • 其他工具
    • 实例1
    • vim安装及配置
    • rust analyzer速度慢
  • rust基础
    • 关键字
    • 模块module和测试
    • 变量-数据类型
      • 浮点数
      • NaN
      • 有理数和复数
    • 单元类型
    • 字符串-切片-数组-元组-hashpmap
    • 结构体和枚举
    • 控制语句
    • 模式匹配match
    • 函数-method 闭包 迭代器
    • File操作
  • Rust进阶
    • 所有权
      • 所有权基础
      • 如何让函数使用某个值,但不获得其所有权
      • 切片
    • Rust VS C
    • 函数指针
  • Q&A
    • Rust的宏
    • cargo expand
    • web server
    • cargo watch使用
    • lib分类
    • cargo源
  • 参考
    • 博客
    • 项目
  • rust内存泄露
  • 智能指针
  • Tauri类似electron的框架
  • Tokio包使用
  • Rust wasm介绍
  • 多线程
    • C语言
  • Golang语言
    • 项目
  • Java
  • Javascript
Powered by GitBook
On this page
  1. Q&A

cargo watch使用

Previousweb serverNextlib分类

Last updated 2 years ago

cargo install cargo-watch

每当对代码进行更改时,通过在后台自动生成项目,cargo-watch可以有助于缩短修复、编译和运行周期。

默认情况下,该工具只运行Rust的类型检查器(cargo check命令),而不进行代码生成阶段(这需要时间),便缩短了编译时间;还可以使用-x flag 提供一个定制命令来代替cargo check。

一般用于微服务或者本地调试。

cargo watch -q -c -w src -x run

-w 检测watch

-c Change working directory before running command [default: crate root]

-q Suppress output from cargo-watch itself

-x Cargo command(s) to execute on changes [default: check]

框架warp:

main代码

use warp::Filter;

#[tokio::main]
async fn main() {
    // GET /hello/warp => 200 OK with body "Hello, warp!"
    let hello = warp::path!("hello1" / String)
        .map(|name| format!("Hello, {}!", name));

    warp::serve(hello)
        .run(([127, 0, 0, 1], 3030))
        .await;
}

cargo.toml

[package]
name = "warp-server"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
warp = "0.3"
tokio = {version = "1", features = ["full"] }
https://github.com/seanmonstar/warp