actix_embed/
fallback_handler.rs

1use actix_web::{HttpRequest, HttpResponse};
2
3/// Fallback handlers will be called when no matched file could be found.
4pub trait FallbackHandler: 'static + Clone {
5    #[allow(missing_docs)]
6    fn execute(&self, req: &HttpRequest) -> HttpResponse;
7}
8
9impl<T> FallbackHandler for T
10where
11    T: Fn(&HttpRequest) -> HttpResponse + Clone + 'static,
12{
13    fn execute(&self, req: &HttpRequest) -> HttpResponse {
14        (self)(req)
15    }
16}
17
18/// The default fallback handler.
19///
20/// It returns 404 response regardless request information.
21#[derive(Debug, Clone)]
22pub struct DefaultFallbackHandler;
23
24impl FallbackHandler for DefaultFallbackHandler {
25    fn execute(&self, _: &HttpRequest) -> HttpResponse {
26        HttpResponse::NotFound().body("404 Not Found")
27    }
28}