Skip to main content

webx_spa/
assets.rs

1//! Files compiled into the executable, read by path — `std::fs::read` for the
2//! binary itself.
3//!
4//! ```ignore
5//! let config = webx::assets::read_str("config/default.json");
6//! let logo = webx::assets::read("images/logo.png");
7//! ```
8//!
9//! Both read the table linked by `#[webx::main(embed)]` and return `None` when
10//! the file is not embedded, or nothing is. Decoding, caching and path rules are
11//! those of [`EmbeddedAssets::read`].
12
13use crate::EmbeddedAssets;
14
15/// The original contents of an embedded file.
16pub fn read(path: &str) -> Option<&'static [u8]> {
17    EmbeddedAssets::registered()?.read(path)
18}
19
20/// The contents of an embedded file as UTF-8 text; also `None` when it is not
21/// UTF-8.
22pub fn read_str(path: &str) -> Option<&'static str> {
23    EmbeddedAssets::registered()?.read_str(path)
24}