Skip to main content

Module warp

Module warp 

Source
Expand description

warp 0.4 集成。

warp 没有提取器 trait,也没有 with_state —— 它靠闭包捕获把一个 Clone 的值接进过滤器链。所以这里没有 impl,只有一个组合子:

use encryption::guard::Guard;
use encryption::integrations::warp::with_guard;
use warp::Filter;

let guard: Guard = todo!();
let route = warp::path("encrypt")
    .and(with_guard(guard))
    .map(|guard: Guard| guard.encrypt("13800138000".as_bytes()).unwrap().len());

这与 warp 文档里 warp::any().map(move || state.clone()) 的写法是同一件事, 只是把「克隆共享状态」这一步收进了一个有名字的组合子,免得每个项目各写一遍。

Functions§

with_guard
造一个产出 Guard 的过滤器,供 .and(...) 接进路由链。