pub struct Builder<'a> { /* private fields */ }
Expand description
Helper to build Assets
.
Implementations§
source§impl<'a> Builder<'a>
impl<'a> Builder<'a>
sourcepub fn add_file(
&mut self,
http_path: impl Into<Cow<'a, str>>,
fs_path: impl Into<PathBuf>
) -> &mut EntryBuilder<'a>
pub fn add_file( &mut self, http_path: impl Into<Cow<'a, str>>, fs_path: impl Into<PathBuf> ) -> &mut EntryBuilder<'a>
Adds an asset by FS path, to be loaded at runtime (instead of being
embedded into the executable). In prod mode, this is loaded in
Builder::build
. Mounts it under the given HTTP path.
sourcepub fn add_embedded(
&mut self,
http_path: impl Into<Cow<'a, str>>,
entry: &'a EmbeddedEntry
) -> &mut EntryBuilder<'a>
pub fn add_embedded( &mut self, http_path: impl Into<Cow<'a, str>>, entry: &'a EmbeddedEntry ) -> &mut EntryBuilder<'a>
Adds an embedded entry (single file or glob). Just calls
Self::add_embedded_file
or Self::add_embedded_glob
, depending
on entry
. See those functions for more information.
sourcepub fn add_embedded_file(
&mut self,
http_path: impl Into<Cow<'a, str>>,
file: &EmbeddedFile
) -> &mut EntryBuilder<'a>
pub fn add_embedded_file( &mut self, http_path: impl Into<Cow<'a, str>>, file: &EmbeddedFile ) -> &mut EntryBuilder<'a>
Adds an embedded file and mounts it under the given HTTP path.
sourcepub fn add_embedded_glob(
&mut self,
http_path: impl Into<Cow<'a, str>>,
glob: &'a EmbeddedGlob
) -> &mut EntryBuilder<'a>
pub fn add_embedded_glob( &mut self, http_path: impl Into<Cow<'a, str>>, glob: &'a EmbeddedGlob ) -> &mut EntryBuilder<'a>
Adds an embedded glob. All files matching this glob are mounted with
http_path
as prefix. Specifically, all leading glob segments that do
not contain glob characters are stripped, and http_path
is prefixed
in front of the matching files.
For example:
- Consider the following files:
foo/bar/cat.svg
,foo/bar/dog.svg
,foo/not-matching.txt
. - In
embed!
you specifyfoo/bar/*.svg
. - This matches the two SVG files:
foo/bar/cat.svg
andfoo/bar/dog.svg
. - Then you call
add_embedded_glob("animals/", &EMBEDS["foo/bar/*.svg"])
. - The leading non-glob segments of the glob (
foo/bar/*.svg
) arefoo/bar/
, which are removed from the matched files:cat.svg
anddog.svg
. - Finally, the specified
http_path
(animals/
) is prefixed, resulting in:animals/cat.svg
andanimals/dog.svg
.
This might sound complicated but should be fairly straight forward and is, I think, the must useful in practice.
sourcepub async fn build(self) -> Result<Assets, BuildError>
pub async fn build(self) -> Result<Assets, BuildError>
Builds Assets
from the configured assets. In prod mode, everything is
loaded, processed, and assembled into a fast data structure. In dev
mode, those steps are deferred to later.