Add option_asset! to match asset! (#4791)
This commit is contained in:
1 parent
e656bace5c
commit
8adea41efa
5 files changed
+77
-16
No files matched your search
@@ -66,6 +66,24 @@ pub fn asset(input: TokenStream) -> TokenStream {
|
||||
quote! { #asset }.into_token_stream().into()
|
||||
}
|
||||
|
||||
/// Resolve an asset at compile time, returning `None` if the asset does not exist.
|
||||
///
|
||||
/// This behaves like the `asset!` macro when the asset can be resolved, but mirrors
|
||||
/// [`option_env!`](core::option_env) by returning an `Option` instead of emitting a compile error
|
||||
/// when the asset is missing.
|
||||
///
|
||||
/// ```rust
|
||||
/// # use manganis::{asset, option_asset, Asset};
|
||||
/// const REQUIRED: Asset = asset!("/assets/style.css");
|
||||
/// const OPTIONAL: Option<Asset> = option_asset!("/assets/maybe.css");
|
||||
/// ```
|
||||
#[proc_macro]
|
||||
pub fn option_asset(input: TokenStream) -> TokenStream {
|
||||
let asset = parse_macro_input!(input as asset::AssetParser);
|
||||
|
||||
asset.expand_option_tokens().into()
|
||||
}
|
||||
|
||||
/// Generate type-safe and globally-unique CSS identifiers from a CSS module.
|
||||
///
|
||||
/// CSS modules allow you to have unique, scoped and type-safe CSS identifiers. A CSS module is a CSS file with the `.module.css` file extension.
|
||||
|
||||
Reference in new issue
Block a user