Struct reinda::EntryBuilder

source ·
pub struct EntryBuilder<'a> { /* private fields */ }
Expand description

Returned by the various Builder::add_* functions, allowing you to configure added assets.

Implementations§

source§

impl<'a> EntryBuilder<'a>

source

pub fn with_hash(&mut self) -> &mut Self

Adds the hash of this asset’s content to its HTTP filename (in prod mode).

This helps a lot with caching on the web. If you include the content hash in the filename then you can set very strong caching headers, like Cache-control :public, max-age=31536000, immutable, meaning that the browser can cache that file for essentially infinitely long time without relying on If-Modified-Since or E-Tag headers.

In dev mode, hashes are never inserted.

The hash is inserted after the first . in the filename and an additional . is added after the hash. Example: bundle.js.map becomes bundle.sbfNUtVcqxUK.js.map. If there is no . in the filename, a - and then the hash is appended, e.g. foo-sbfNUtVcqxUK.

Method is only available if the crate feature hash is enabled.

source

pub fn with_path_fixup<D, T>(&mut self, paths: D) -> &mut Self
where D: IntoIterator<Item = T>, T: Into<Cow<'static, str>>,

Replaces occurences of any of the given unhashed HTTP paths in this asset with the corresponding hashed HTTP path. This is a specialized version of Self::with_modifier.

source

pub fn with_modifier<F, D, T>( &mut self, dependencies: D, modifier: F ) -> &mut Self
where F: 'static + Send + Sync + Fn(Bytes, ModifierContext<'_>) -> Bytes, D: IntoIterator<Item = T>, T: Into<Cow<'static, str>>,

Registers a modifier that modifies this asset’s content, being able to resolve unhashed HTTP paths to hashed HTTP paths.

If you just need to replace paths, Self::with_path_fixup might work for you. This is the more powerful version, allowing you to perform arbitrary logic with the asset’s content. In prod mode, this is called once when you call Builder::build; in dev mode, it’s called every time the asset is loaded.

source

pub fn http_paths(&self) -> Vec<Cow<'a, str>>

Returns all unhashed HTTP paths that are mounted by this entry. This is mainly useful to pass as dependencies to Self::with_modifier or Self::with_path_fixup of another entry.

source

pub fn single_http_path(&self) -> Option<Cow<'a, str>>

Like Self::http_paths but asserting that there is only one path added by this entry. If that’s not the case, None is returned.

Trait Implementations§

source§

impl<'a> Debug for EntryBuilder<'a>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !Freeze for EntryBuilder<'a>

§

impl<'a> !RefUnwindSafe for EntryBuilder<'a>

§

impl<'a> Send for EntryBuilder<'a>

§

impl<'a> Sync for EntryBuilder<'a>

§

impl<'a> Unpin for EntryBuilder<'a>

§

impl<'a> !UnwindSafe for EntryBuilder<'a>

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.