disco-assets 0.2.2

Assets crate generated by rlvgl-creator for the rlvgl STM32H747I-DISCO demo
Documentation
#![no_std]
#![deny(missing_docs)]
//! Assets crate generated by rlvgl-creator.

#[cfg(feature = "vendor")]
extern crate std;

#[cfg(feature = "embed")]
/// Embedded asset bytes.
pub mod embed {
    use phf::{Map, phf_map};

    pub const MEDIA_SPLASH_RAW: &[u8] =
        include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../media/splash.raw"));
    pub const MEDIA_ALCHEMIST_404_RAW: &[u8] = include_bytes!(concat!(
        env!("CARGO_MANIFEST_DIR"),
        "/../media/alchemist-404.raw"
    ));
    pub const MEDIA_ALCHEMIST_500_RAW: &[u8] = include_bytes!(concat!(
        env!("CARGO_MANIFEST_DIR"),
        "/../media/alchemist-500.raw"
    ));
    pub const MEDIA_OAK_WOOD_GRAIN_RAW: &[u8] = include_bytes!(concat!(
        env!("CARGO_MANIFEST_DIR"),
        "/../media/oak-wood-grain.raw"
    ));
    pub const ICON_FAVICON_RAW: &[u8] =
        include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../icons/favicon.raw"));
    pub const ICON_FILE_RAW: &[u8] =
        include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../icons/file.raw"));
    pub const ICON_GLOBE_RAW: &[u8] =
        include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../icons/globe.raw"));
    pub const ICON_SOFT_O_OUTLINE_YELLOW_RAW: &[u8] = include_bytes!(concat!(
        env!("CARGO_MANIFEST_DIR"),
        "/../icons/soft-o-outline-yellow.raw"
    ));
    pub const ICON_SOFTOBOROS_LETTER_LOGO_RAW: &[u8] = include_bytes!(concat!(
        env!("CARGO_MANIFEST_DIR"),
        "/../icons/softoboros-letter-logo.raw"
    ));
    pub const ICON_WINDOW_RAW: &[u8] =
        include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../icons/window.raw"));

    static INDEX: Map<&'static str, &'static [u8]> = phf_map! {

        "media/splash.raw" => MEDIA_SPLASH_RAW,
        "media/alchemist-404.raw" => MEDIA_ALCHEMIST_404_RAW,
        "media/alchemist-500.raw" => MEDIA_ALCHEMIST_500_RAW,
        "media/oak-wood-grain.raw" => MEDIA_OAK_WOOD_GRAIN_RAW,
        "icons/favicon.raw" => ICON_FAVICON_RAW,
        "icons/file.raw" => ICON_FILE_RAW,
        "icons/globe.raw" => ICON_GLOBE_RAW,
        "icons/soft-o-outline-yellow.raw" => ICON_SOFT_O_OUTLINE_YELLOW_RAW,
        "icons/softoboros-letter-logo.raw" => ICON_SOFTOBOROS_LETTER_LOGO_RAW,
        "icons/window.raw" => ICON_WINDOW_RAW,

    };

    /// Fetch an embedded asset by its relative path.
    pub fn get(path: &str) -> Option<&'static [u8]> {
        INDEX.get(path).copied()
    }
}

#[cfg(feature = "vendor")]
/// Vendor build helpers.
pub mod vendor {
    use std::path::Path;

    /// Copy all assets into `out_dir`.
    pub fn copy_all(out_dir: &Path) -> std::io::Result<()> {
        vendor_api::copy_all(out_dir, ASSETS)
    }

    /// Generate an `rlvgl_assets.rs` module under `out_dir`.
    pub fn generate_rust_module(out_dir: &Path) -> std::io::Result<()> {
        vendor_api::generate_rust_module(out_dir, ASSETS)
    }

    const ASSETS: &[(&str, &str)] = &[
        ("MEDIA_SPLASH_RAW", "media/splash.raw"),
        ("MEDIA_ALCHEMIST_404_RAW", "media/alchemist-404.raw"),
        ("MEDIA_ALCHEMIST_500_RAW", "media/alchemist-500.raw"),
        ("MEDIA_OAK_WOOD_GRAIN_RAW", "media/oak-wood-grain.raw"),
        ("ICON_FAVICON_RAW", "icons/favicon.raw"),
        ("ICON_FILE_RAW", "icons/file.raw"),
        ("ICON_GLOBE_RAW", "icons/globe.raw"),
        (
            "ICON_SOFT_O_OUTLINE_YELLOW_RAW",
            "icons/soft-o-outline-yellow.raw",
        ),
        (
            "ICON_SOFTOBOROS_LETTER_LOGO_RAW",
            "icons/softoboros-letter-logo.raw",
        ),
        ("ICON_WINDOW_RAW", "icons/window.raw"),
    ];

    mod vendor_api {
        use std::{format, fs, path::Path, string::String};

        pub fn copy_all(out_dir: &Path, assets: &[(&str, &str)]) -> std::io::Result<()> {
            let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../");
            for (_, path) in assets {
                let src = root.join(path);
                let dest = out_dir.join(path);
                if let Some(parent) = dest.parent() {
                    fs::create_dir_all(parent)?;
                }
                fs::copy(&src, &dest)?;
            }
            Ok(())
        }

        pub fn generate_rust_module(
            out_dir: &Path,
            assets: &[(&str, &str)],
        ) -> std::io::Result<()> {
            let mut module = String::from("//! Auto-generated asset constants\n\n");
            for (name, path) in assets {
                module.push_str(&format!(
                    "pub const {}: &[u8] = include_bytes!(\"{}\");\n",
                    name, path
                ));
            }
            fs::write(out_dir.join("rlvgl_assets.rs"), module)?;
            Ok(())
        }
    }
}