Expand description
§mbed
Embed and transform assets into your Rust crate.
mbed provides macros for turning files and generated outputs into Artifact
values. Artifacts carry their bytes, MIME type, and Id, and can be grouped
into a Manifest for lookup by identifier.
§Basic usage
Requires the macros feature.
pub const LOGO: Artifact<[u8]> = mbed::include_bytes!["../assets/logo.svg"];
pub const INDEX: Artifact<str> = mbed::include_str!["../pages/index.html"];
let id = LOGO.id();
assert_eq!(LOGO.mime(), "image/svg+xml");§Collections and manifests
collect! groups artifacts inside a module. manifest! can then reference
individual artifacts or whole collections with ::*.
Requires the macros feature.
pub mod pages {
pub const INDEX: Artifact<str> = mbed::include_str!["../pages/index.html"];
pub const ABOUT: Artifact<str> = mbed::include_str!["../pages/about.html"];
mbed::collect![INDEX, ABOUT];
}
pub mod images {
pub const LOGO: Artifact<[u8]> = mbed::include_bytes!["../assets/logo.svg"];
mbed::collect![LOGO];
}
pub const ASSETS: Manifest = mbed::manifest![pages::*, images::*];
let artifact = ASSETS.get(pages::INDEX.id()).unwrap();
assert_eq!(artifact.mime(), pages::INDEX.mime());§Images
Requires the image feature.
pub const LOGO: Artifact<Image> = mbed::image::include! {
resize: Scale(0.5),
path: "../assets/logo.png",
format: WebP,
};
assert_eq!(LOGO.format(), mbed::image::Format::WebP);
let bytes = LOGO.as_bytes();§JavaScript bundles
Requires the bundle feature.
pub const APP: Artifact<Bundle> = mbed::js::bundle!["../frontend/app.js"];
let code = APP.code();
let sourcemap = APP.sourcemap();§Tailwind CSS
Requires the tailwindcss feature.
pub const STYLES: Artifact<str> = mbed::css::tailwindcss!("../tailwind.css");§Feature flags
macrosenablesinclude_bytes!,include_str!,collect!, andmanifest!.imageenablesimage::include!and image metadata support.bundleenablesjs::bundle!.tailwindcssenablescss::tailwindcss!.serdeenables serialization support for public data types.cargo-progressshows bundling progress in Cargo build output. This feature is only supported on Linux.
Modules§
Macros§
- collect
macros - Groups artifacts into a module-local collection.
- include_
bytes macros - Embeds a UTF-8 file as an
Artifact<str>. - include_
str macros - Embeds a file as an [
Artifact<[u8]>]. - manifest
macros - Builds a
Manifestfrom artifacts and collections.