Struct WebAssets

Source
pub struct WebAssets { /* private fields */ }

Implementations§

Source§

impl WebAssets

Source

pub fn new<S: Into<String>, P: Into<PathBuf>>(identifier: S, path: P) -> Self

Creates a new WebAssets Pipeline

By default the filter list type is a blacklist.

Source

pub fn filter(self, filter: Filter) -> Self

Add a filter to the pipeline

Filters are applied in the order that they were added, the first matching filter determines how the file entry is handled. If you want to include all javascript files, but not the ones in a certain folder, then you should add the exclusion rule first, and then the inclusion filter.

If there are no filters then all files are matched. If there are no filters and it’s a whitelist, no files are matched.

§Examples

Matching everything except css and json files:

WebAssets::new("NON_IMAGE_ASSETS", "../resources")
    .filter(Filter::exclude_extension("css"))
    .filter(Filter::exclude_extension("json"));

Include all javascript files, but exclude all in the adminsubdirectory:

WebAssets::new("ASSETS", "./web/dist")
    .whitelist()
    .filter(Filter::exclude_regex(r"^admin/.*$"))
    .filter(Filter::include_extension("js"));

If you wanted to only match text and markdown files:

WebAssets::new("ASSETS", "../notes")
    .whitelist()
    .filter(Filter::include_extension("txt"))
    .filter(Filter::include_extension("md"));

or to include all css files in a subdirectory styles:

WebAssets::new("ASSETS", "../web/dist")
    .whitelist()
    .filter(Filter::include_regex(r"^styles/.*\.css$"));

NOTE: If you need to care about multi-platform it’s your responsibility to use a proper regex that accounts for the proper path separator. See FilterRule::regex for examples that account for this. AFAIK std::path doesn’t normalize the separators.

Source

pub fn prefix<S: Into<String>>(self, prefix: S) -> Self

Sets the prefix to use for the normalized path uri.

This is relative to where your asset path is. If your asset path is "./web/dist/assets", with your web root being at "./web/dist", then having a prefix of "/assets" would make the relative URIs align with your web root to make the hit URL correct.

Defaults to "/"

Source

pub fn set_path<P: Into<PathBuf>>(self, path: P) -> Self

Sets the path to the assets directory.

Source

pub fn blacklist(self) -> Self

Set the filter list type to a blacklist.

Source

pub fn whitelist(self) -> Self

Set the filter list type to a whitelist.

Source

pub fn build(self) -> Box<Self>

Boxes up the pipeline to pass to Codegen easily.

Source

pub fn brotli(self, brotli: bool) -> Self

Sets whether to include the brotli version of every file too

Source

pub fn gzip(self, gzip: bool) -> Self

Sets whether to include the gzip version of every file too

Trait Implementations§

Source§

impl Display for WebAssets

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Pipeline for WebAssets

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.