AssetOptionsBuilder

Struct AssetOptionsBuilder 

Source
pub struct AssetOptionsBuilder<T> { /* private fields */ }
Expand description

A builder for AssetOptions

static ASSET: Asset = asset!(
    "/assets/style.css",
    AssetOptions::builder()
    .with_hash_suffix(false)
);

Implementations§

Source§

impl AssetOptionsBuilder<FolderAssetOptions>

Source

pub const fn into_asset_options(self) -> AssetOptions

Convert the options into options for a generic asset

Source§

impl AssetOptionsBuilder<ImageAssetOptions>

Source

pub const fn with_preload(self, preload: bool) -> Self

Make the asset preloaded

Preloading an image will make the image start to load as soon as possible. This is useful for images that will be displayed soon after the page loads or images that may not be visible immediately, but should start loading sooner

const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_preload(true));
Source

pub const fn with_format(self, format: ImageFormat) -> Self

Sets the format of the image

Choosing the right format can make your site load much faster. Webp and avif images tend to be a good default for most images

const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_format(ImageFormat::Webp));
Source

pub const fn with_avif(self) -> Self

Sets the format of the image to ImageFormat::Avif

Avif images tend to be a good default for most images rendered in browser because they compress images well

const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_avif());
Source

pub const fn with_webp(self) -> Self

Sets the format of the image to ImageFormat::Webp

Webp images tend to be a good default for most images rendered in browser because they compress images well

const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_webp());
Source

pub const fn with_jpg(self) -> Self

Sets the format of the image to ImageFormat::Jpg

Jpeg images compress much better than ImageFormat::Png, but worse than ImageFormat::Webp or ImageFormat::Avif

const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_jpg());
Source

pub const fn with_png(self) -> Self

Sets the format of the image to ImageFormat::Png

Png images don’t compress very well, so they are not recommended for large images

const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_png());
Source

pub const fn with_size(self, size: ImageSize) -> Self

Sets the size of the image

If you only use the image in one place, you can set the size of the image to the size it will be displayed at. This will make the image load faster

const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_size(ImageSize::Manual { width: 512, height: 512 }));
Source

pub const fn into_asset_options(self) -> AssetOptions

Convert the options into options for a generic asset

Source§

impl AssetOptionsBuilder<()>

Source

pub const fn new() -> Self

Create a new asset options builder with an unknown variant

Source

pub const fn default() -> Self

Create a default asset options builder

Source

pub const fn into_asset_options(self) -> AssetOptions

Convert the builder into asset options with the given variant

Source§

impl<T> AssetOptionsBuilder<T>

Source

pub const fn with_hash_suffix(self, add_hash: bool) -> Self

Set whether a hash should be added to the asset path. Manganis adds hashes to asset paths by default for cache busting. With hashed assets, you can serve the asset with a long expiration time, and when the asset changes, the hash in the path will change, causing the browser to fetch the new version.

This method will only effect if the hash is added to the bundled asset path. If you are using the asset macro, the asset struct still needs to be used in your rust code to ensure the asset is included in the binary.

If you are using an asset outside of rust code where you know what the asset hash will be, you must use the #[used] attribute to ensure the asset is included in the binary even if it is not referenced in the code.

#[used]
static ASSET: manganis::Asset = manganis::asset!(
    "/assets/style.css",
    manganis::AssetOptions::builder()
        .with_hash_suffix(false)
);
Source§

impl AssetOptionsBuilder<CssAssetOptions>

Source

pub const fn with_minify(self, minify: bool) -> Self

Sets whether the css should be minified (default: true)

Minifying the css can make your site load faster by loading less data

const _: Asset = asset!("/assets/style.css", AssetOptions::css().with_minify(false));
Source

pub const fn with_static_head(self, static_head: bool) -> Self

Make the asset statically inserted (default: false)

Statically insert the file at compile time.

const _: Asset = asset!("/assets/style.css", AssetOptions::css().with_static_head(true));
Source

pub const fn with_preload(self, preload: bool) -> Self

Make the asset preloaded

Preloading css will make the file start to load as soon as possible. This is useful for css that is used soon after the page loads or css that may not be used immediately, but should start loading sooner

const _: Asset = asset!("/assets/style.css", AssetOptions::css().with_preload(true));
Source

pub const fn into_asset_options(self) -> AssetOptions

Convert the options into options for a generic asset

Source§

impl AssetOptionsBuilder<JsAssetOptions>

Source

pub const fn with_minify(self, minify: bool) -> Self

Sets whether the js should be minified (default: true)

Minifying the js can make your site load faster by loading less data

const _: Asset = asset!("/assets/script.js", AssetOptions::js().with_minify(false));
Source

pub const fn with_static_head(self, static_head: bool) -> Self

Make the asset statically inserted (default: false)

Statically insert the file at compile time.

const _: Asset = asset!("/assets/script.js", AssetOptions::js().with_static_head(true));
Source

pub const fn with_preload(self, preload: bool) -> Self

Make the asset preloaded

Preloading the javascript will make the javascript start to load as soon as possible. This is useful for javascript that will be used soon after the page loads or javascript that may not be used immediately, but should start loading sooner

const _: Asset = asset!("/assets/script.js", AssetOptions::js().with_preload(true));
Source

pub const fn into_asset_options(self) -> AssetOptions

Convert the builder into asset options with the given variant

Source§

impl AssetOptionsBuilder<CssModuleAssetOptions>

Source

pub const fn with_minify(self, minify: bool) -> Self

Sets whether the css should be minified (default: true)

Minifying the css can make your site load faster by loading less data

Source

pub const fn with_preload(self, preload: bool) -> Self

Make the asset preloaded

Preloading css will make the image start to load as soon as possible. This is useful for css that is used soon after the page loads or css that may not be used immediately, but should start loading sooner

Source

pub const fn into_asset_options(self) -> AssetOptions

Convert the options into options for a generic asset

Trait Implementations§

Source§

impl Default for AssetOptionsBuilder<()>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for AssetOptionsBuilder<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for AssetOptionsBuilder<T>
where T: RefUnwindSafe,

§

impl<T> Send for AssetOptionsBuilder<T>
where T: Send,

§

impl<T> Sync for AssetOptionsBuilder<T>
where T: Sync,

§

impl<T> Unpin for AssetOptionsBuilder<T>
where T: Unpin,

§

impl<T> UnwindSafe for AssetOptionsBuilder<T>
where T: UnwindSafe,

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

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.