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>
impl<'a> EntryBuilder<'a>
sourcepub fn with_hash(&mut self) -> &mut Self
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.
sourcepub fn with_path_fixup<D, T>(&mut self, paths: D) -> &mut Self
pub fn with_path_fixup<D, T>(&mut self, paths: D) -> &mut Self
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
.
sourcepub fn with_modifier<F, D, T>(
&mut self,
dependencies: D,
modifier: F
) -> &mut Selfwhere
F: 'static + Send + Sync + Fn(Bytes, ModifierContext<'_>) -> Bytes,
D: IntoIterator<Item = T>,
T: Into<Cow<'static, str>>,
pub fn with_modifier<F, D, T>(
&mut self,
dependencies: D,
modifier: F
) -> &mut Selfwhere
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.
sourcepub fn http_paths(&self) -> Vec<Cow<'a, str>>
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.
sourcepub fn single_http_path(&self) -> Option<Cow<'a, str>>
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.