Skip to main content

Module salvo

Module salvo 

Source
Expand description

salvo 1.0 集成。

用 affix_state 把守卫放进 Depot,处理器用 Extractible 取出来:

use encryption::guard::Guard;
use salvo::prelude::*;

#[handler]
async fn store_phone(guard: Guard) -> String {
    guard.encrypt("13800138000".as_bytes()).unwrap().len().to_string()
}

// 注册(`affix_state` 挂在 salvo 的 `affix-state` feature 后面,
// 需要 `cargo add salvo --features affix-state` 才能引用):
//   Router::new().hoop(affix_state::inject(guard)).get(store_phone)

§注意 salvo 1.0 的破坏性变更

salvo 1.0(2026-09-24 发布)把状态中间件挪到了 salvo_extra::affix_state,且改为返回 AffixList 的自由函数 (affix_state::inject(v))。网上大量写于 0.7x/0.96 的 Depot::inject、 Router::aim 用法的资料对 1.x 不适用。