asset

Macro asset 

Source
asset!() { /* proc-macro */ }
Expand description

The asset macro collects assets that will be included in the final binary

§Files

The file builder collects an arbitrary file. Relative paths are resolved relative to the package root

const _: Asset = asset!("/assets/asset.txt");

§Images

You can collect images which will be automatically optimized with the image builder:

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

Resize the image at compile time to make the assets file size smaller:

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

Or convert the image at compile time to a web friendly format:

const _: Asset = asset!("/assets/image.png", ImageAssetOptions::new().with_format(ImageFormat::Avif));

You can mark images as preloaded to make them load faster in your app

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