【Rust】axumのlayer middlewareにstateを渡す方法

from_fn_with_state という書き方がある。
https://docs.rs/axum/latest/axum/middleware/fn.from_fn_with_state.html

    let app_state = model::connection_pool().await.unwrap();
    let app = Router::new()
        .route("/", get(handler))
        .layer(middleware::from_fn_with_state(app_state.clone(),auth_middleware))
        .layer(CsrfLayer::new(config))
        .with_state(app_state);
//

pub async fn auth_middleware(State(state): State<model::AppState>, req: Request,
    next: Next) -> impl IntoResponse {

    let res = next.run(req).await;
    res   
}

なるほどね、先回りしてよく作られてるw