pub struct StaticFiles { /* private fields */ }Expand description
Serves files from a directory. Build with StaticFiles::dir, then mount
its handler on a {path...} wildcard route.
Implementations§
Source§impl StaticFiles
impl StaticFiles
Sourcepub fn list_directories(self, yes: bool) -> Self
pub fn list_directories(self, yes: bool) -> Self
List a directory’s contents when it has no index file.
Off by default, and deliberately so: a listing discloses every filename under the served root, which is how backup files, editor swap files and forgotten exports get found. Turn it on for a file mirror, not for an application’s assets.
Sourcepub fn index(self, file: impl Into<String>) -> Self
pub fn index(self, file: impl Into<String>) -> Self
Serve <dir>/<index> when a request resolves to a directory.
Sourcepub fn handler(self) -> impl Handler
pub fn handler(self) -> impl Handler
Turn this into a Handler for a wildcard route. The handler reads the
route’s single captured path parameter as the relative path.
§Panics
Panics if the root does not exist or is not a directory. This is a
configuration mistake, and the alternative is worse: the previous
behaviour returned 500 on every request, forever, for a typo that
could have been caught at startup.
Use try_handler to handle it yourself.
Sourcepub fn try_handler(self) -> Option<impl Handler>
pub fn try_handler(self) -> Option<impl Handler>
Like handler but returns None instead of
panicking when the root is unusable.
Trait Implementations§
Source§impl Clone for StaticFiles
impl Clone for StaticFiles
Source§fn clone(&self) -> StaticFiles
fn clone(&self) -> StaticFiles
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more