Macro manganis::mg

source ·
mg!() { /* proc-macro */ }
Expand description

The mg 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 _: &str = manganis::mg!(file("./src/asset.txt"));

Or you can use URLs to read the asset at build time from a remote location

const _: &str = manganis::mg!(file("https://rustacean.net/assets/rustacean-flat-happy.png"));

§Images

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

const _: &str = manganis::mg!(image("./rustacean-flat-gesture.png"));

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

const _: &str = manganis::mg!(image("./rustacean-flat-gesture.png").size(52, 52));

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

const _: &str = manganis::mg!(image("./rustacean-flat-gesture.png").format(ImageFormat::Avif).size(52, 52));

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

const _: &str = manganis::mg!(image("./rustacean-flat-gesture.png").preload());

§Fonts

You can use the font builder to collect fonts that will be included in the final binary from google fonts

const _: &str = manganis::mg!(font().families(["Roboto"]));

You can specify weights for the fonts

const _: &str = manganis::mg!(font().families(["Roboto"]).weights([200]));

Or set the text to only include the characters you need

const _: &str = manganis::mg!(font().families(["Roboto"]).weights([200]).text("Hello, world!"));