assets

Embedded static assets served via rust-embed.

struct StaticAssets

source

struct StaticAssets;

The .css and .js files under templates/, embedded in the binary at build time.

Implements RustEmbed.

StaticAssets::matcher

source

fn matcher() -> PathMatcher
Parameter Type Description
returns PathMatcher

StaticAssets::get

source

pub fn get(file_path: &str) -> Option<EmbeddedFile>

Get an embedded file and its metadata.

Parameter Type Description
file_path &str
returns Option<EmbeddedFile>

StaticAssets::iter

source

pub fn iter() -> impl Iterator<Item = Cow<'static, str>> + 'static

Iterates over the file paths in the folder.

Parameter Type Description
returns impl Iterator<Item = Cow<'static, str>> + 'static

fn serve

source

pub async fn serve(Path(path): Path<String>) -> Response

Serve an embedded static asset by path.

Parameter Type Description
Path(path) Path<String> the asset’s path under templates/, from the /static/{*path} route
returns Response The asset’s bytes with a Content-Type from its extension, or an empty 404 response when no embedded asset has that path.

fn mime_for

source

fn mime_for(path: &str) -> &'static str

Infer a MIME type from the file extension.

Parameter Type Description
path &str the asset’s path
returns &'static str The UTF-8 CSS or JavaScript type for .css and .js, and application/octet-stream for any other extension.