pub trait StaticFiles: Send + Sync {
// Required methods
fn serve_index(&self, headers: &HeaderMap) -> Option<Response<Bytes>>;
fn matches(&self, path: &str) -> bool;
fn serve_file_only(
&self,
path: &str,
headers: &HeaderMap,
) -> Option<Response<Bytes>>;
// Provided methods
fn is_spa(&self) -> bool { ... }
fn serve_not_found(&self, _headers: &HeaderMap) -> Option<Response<Bytes>> { ... }
}Expand description
Trait for serving static files (filesystem or embedded).
Implemented by StaticFileHandler and EmbeddedStaticFileHandler.
The router stores Option<Arc<dyn StaticFiles>> to serve files
without knowing the concrete handler type.
Required Methods§
Provided Methods§
Sourcefn serve_not_found(&self, _headers: &HeaderMap) -> Option<Response<Bytes>>
fn serve_not_found(&self, _headers: &HeaderMap) -> Option<Response<Bytes>>
Serve the configured custom 404 page, if any. Distinct from
Self::serve_index (the SPA fallback): this returns a 404
status with the user-authored not-found body (typically from
[package.metadata.app.static].not_found). Returns None when
no custom 404 is configured — the router falls back to its
platform JSON 404 in that case.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".