#[non_exhaustive]pub struct StaticDir {
pub roots: Vec<PathBuf>,
pub chunk_size: Option<u64>,
pub include_dot_files: bool,
pub auto_list: bool,
pub compressed_variations: HashMap<CompressionAlgo, Vec<String>>,
pub defaults: Vec<String>,
pub fallback: Option<String>,
/* private fields */
}Expand description
Handler that serves static files from directories.
This handler can serve files from one or more directory paths, with support for directory listing, compressed file variants, and default files.
§Examples
use salvo_core::prelude::*;
use salvo_serve_static::StaticDir;
let router = Router::new()
.push(Router::with_path("static/<**>")
.get(StaticDir::new(["assets", "static"])
.defaults("index.html")
.auto_list(true)));Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.roots: Vec<PathBuf>Static root directories to search for files
chunk_size: Option<u64>Chunk size for file reading (in bytes)
include_dot_files: boolWhether to include dot files (files/directories starting with .)
auto_list: boolWhether to automatically list directories when default file isn’t found
compressed_variations: HashMap<CompressionAlgo, Vec<String>>Map of compression algorithms to file extensions for compressed variants
defaults: Vec<String>Default file names to look for in directories (e.g., “index.html”)
fallback: Option<String>Fallback file to serve when requested file isn’t found
Implementations§
Source§impl StaticDir
impl StaticDir
Sourcepub fn new<T>(roots: T) -> StaticDirwhere
T: StaticRoots,
pub fn new<T>(roots: T) -> StaticDirwhere
T: StaticRoots,
Create new StaticDir.
Sourcepub fn include_dot_files(self, include_dot_files: bool) -> StaticDir
pub fn include_dot_files(self, include_dot_files: bool) -> StaticDir
Sets include_dot_files.
Sourcepub fn exclude<F>(self, filter: F) -> StaticDir
pub fn exclude<F>(self, filter: F) -> StaticDir
Exclude files.
The filter function returns true to exclude the file.
Sourcepub fn compressed_variation<A>(self, algo: A, exts: &str) -> StaticDirwhere
A: Into<CompressionAlgo>,
pub fn compressed_variation<A>(self, algo: A, exts: &str) -> StaticDirwhere
A: Into<CompressionAlgo>,
Sets compressed_variations.
Sourcepub fn chunk_size(self, size: u64) -> StaticDir
pub fn chunk_size(self, size: u64) -> StaticDir
During the file chunk read, the maximum read size at one time will affect the access experience and the demand for server memory.
Please set it according to your own situation.
The default is 1M.
Trait Implementations§
Source§impl Handler for StaticDir
impl Handler for StaticDir
Source§fn handle<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
req: &'life1 mut Request,
_depot: &'life2 mut Depot,
res: &'life3 mut Response,
_ctrl: &'life4 mut FlowCtrl,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
StaticDir: 'async_trait,
fn handle<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
req: &'life1 mut Request,
_depot: &'life2 mut Depot,
res: &'life3 mut Response,
_ctrl: &'life4 mut FlowCtrl,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
StaticDir: 'async_trait,
Source§fn arc(self) -> ArcHandlerwhere
Self: Sized,
fn arc(self) -> ArcHandlerwhere
Self: Sized,
ArcHandler.