logo

Function actix_web::guard::fn_guard[][src]

pub fn fn_guard<F>(f: F) -> impl Guard where
    F: Fn(&RequestHead) -> bool
Expand description

Create guard object for supplied function.

use actix_web::{guard, web, App, HttpResponse};

App::new().service(web::resource("/index.html").route(
    web::route()
        .guard(
            guard::fn_guard(
                |req| req.headers()
                         .contains_key("content-type")))
        .to(|| HttpResponse::MethodNotAllowed()))
);