manganis_macro/
lib.rs

1#![doc = include_str!("../README.md")]
2#![deny(missing_docs)]
3
4use proc_macro::TokenStream;
5use quote::{quote, ToTokens};
6use syn::parse_macro_input;
7
8pub(crate) mod asset;
9pub(crate) mod linker;
10
11use linker::generate_link_section;
12
13/// The asset macro collects assets that will be included in the final binary
14///
15/// # Files
16///
17/// The file builder collects an arbitrary file. Relative paths are resolved relative to the package root
18/// ```rust
19/// # use manganis::{asset, Asset};
20/// const _: Asset = asset!("/assets/asset.txt");
21/// ```
22///
23/// # Images
24///
25/// You can collect images which will be automatically optimized with the image builder:
26/// ```rust
27/// # use manganis::{asset, Asset};
28/// const _: Asset = asset!("/assets/image.png");
29/// ```
30/// Resize the image at compile time to make the assets file size smaller:
31/// ```rust
32/// # use manganis::{asset, Asset, ImageAssetOptions, ImageSize};
33/// const _: Asset = asset!("/assets/image.png", ImageAssetOptions::new().with_size(ImageSize::Manual { width: 52, height: 52 }));
34/// ```
35/// Or convert the image at compile time to a web friendly format:
36/// ```rust
37/// # use manganis::{asset, Asset, ImageAssetOptions, ImageSize, ImageFormat};
38/// const _: Asset = asset!("/assets/image.png", ImageAssetOptions::new().with_format(ImageFormat::Avif));
39/// ```
40/// You can mark images as preloaded to make them load faster in your app
41/// ```rust
42/// # use manganis::{asset, Asset, ImageAssetOptions};
43/// const _: Asset = asset!("/assets/image.png", ImageAssetOptions::new().with_preload(true));
44/// ```
45#[proc_macro]
46pub fn asset(input: TokenStream) -> TokenStream {
47    let asset = parse_macro_input!(input as asset::AssetParser);
48
49    quote! { #asset }.into_token_stream().into()
50}