Skip to main content

Module poem

Module poem 

Source
Expand description

poem 3 集成。

用 .data(guard) 注册,处理器把守卫写在参数里:

use poem::{EndpointExt, Route, get, handler};
use encryption::guard::Guard;

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

let guard: Guard = todo!();
let app = Route::new().at("/", get(store_phone)).data(guard);

poem 的 .data(v) 要求 T: Clone + Send + Sync + 'static;Guard 满足, 且克隆的只是一次 Arc 引用计数递增。