Files
dioxus/packages/manganis/manganis-core/src/options.rs
T
Evan Almloff f9617c8d33 Restore manganis optimizations (#3195)
* Create a crate for constant serialization of config structs for manganis
* use SerializeConst for the image asset builder
* switch to a declarative macro for assets
* add serializable options for each asset type
* implement the new manganis macro
* optimize assets in the CLI
* Fix assets with dioxus formattable
* reduce fuzzing test limits
* use the new syntax in examples
* fix avif support
* Fix manganis doc tests
* cache asset optimization
* Split out asset and bundled asset
* make hash pointer width independent
* Fix manganis macro docs
* add constvec::is_empty method to fix clippy lint
* remove nasm feature
* simplify test_rsplit_once test so typos passes
* revert example change from clippy fix
* always accept unix paths
* fix windows path seperator
* fix folder asset hash
* Optimize assets in a blocking task
* Fix asset options docs
* Document Asset and BundledAsset
* simplify the linker macro a bit
* add more docs to AssetParser expansion
* add image format helpers
* Split by  both unix and windows path separators and take the smallest one
2024-11-26 18:12:24 +01:00

49 lines
1.2 KiB
Rust

use const_serialize::SerializeConst;
use crate::{CssAssetOptions, FolderAssetOptions, ImageAssetOptions, JsAssetOptions};
/// Settings for a generic asset
#[derive(
Debug,
PartialEq,
PartialOrd,
Clone,
Copy,
Hash,
SerializeConst,
serde::Serialize,
serde::Deserialize,
)]
#[repr(C, u8)]
#[non_exhaustive]
pub enum AssetOptions {
/// An image asset
Image(ImageAssetOptions),
/// A folder asset
Folder(FolderAssetOptions),
/// A css asset
Css(CssAssetOptions),
/// A javascript asset
Js(JsAssetOptions),
/// An unknown asset
Unknown,
}
impl AssetOptions {
/// Try to get the extension for the asset. If the asset options don't define an extension, this will return None
pub const fn extension(&self) -> Option<&'static str> {
match self {
AssetOptions::Image(image) => image.extension(),
AssetOptions::Css(_) => Some("css"),
AssetOptions::Js(_) => Some("js"),
AssetOptions::Folder(_) => None,
AssetOptions::Unknown => None,
}
}
/// Convert the options into options for a generic asset
pub const fn into_asset_options(self) -> Self {
self
}
}