Struct reinda::Builder

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

Helper to build Assets.

Implementations§

source§

impl<'a> Builder<'a>

source

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.

source

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.

source

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.

source

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 specify foo/bar/*.svg.
  • This matches the two SVG files: foo/bar/cat.svg and foo/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) are foo/bar/, which are removed from the matched files: cat.svg and dog.svg.
  • Finally, the specified http_path (animals/) is prefixed, resulting in: animals/cat.svg and animals/dog.svg.

This might sound complicated but should be fairly straight forward and is, I think, the must useful in practice.

source

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.

Trait Implementations§

source§

impl<'a> Debug for Builder<'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 Builder<'a>

§

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

§

impl<'a> Send for Builder<'a>

§

impl<'a> Sync for Builder<'a>

§

impl<'a> Unpin for Builder<'a>

§

impl<'a> !UnwindSafe for Builder<'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.