pub struct EmbeddedAssets { /* private fields */ }Expand description
A build-time directory tree of static files.
Implementations§
Source§impl EmbeddedAssets
impl EmbeddedAssets
Sourcepub const fn new(
root: &'static str,
files: &'static [EmbeddedAsset],
) -> EmbeddedAssets
pub const fn new( root: &'static str, files: &'static [EmbeddedAsset], ) -> EmbeddedAssets
Wrap a table produced by generated code.
root is the directory the bytes were compiled from, as written by the
caller (e.g. "wwwroot"), and is used as the disk overlay directory when
no use_spa(...) call named one.
Sourcepub const fn root(&self) -> &'static str
pub const fn root(&self) -> &'static str
The directory the bytes were compiled from, as written by the caller.
Sourcepub const fn files(&self) -> &'static [EmbeddedAsset]
pub const fn files(&self) -> &'static [EmbeddedAsset]
The table, sorted by EmbeddedAsset::path.
Sourcepub fn total_bytes(&self) -> u64
pub fn total_bytes(&self) -> u64
Combined size of the stored payloads, in bytes — what the binary holds.
Sourcepub fn total_raw_bytes(&self) -> u64
pub fn total_raw_bytes(&self) -> u64
Combined size of the files as they exist on disk.
Larger than total_bytes whenever something was
compressed; the difference is what brotli saved.
Sourcepub fn get(&self, path: &str) -> Option<&'static EmbeddedAsset>
pub fn get(&self, path: &str) -> Option<&'static EmbeddedAsset>
Look up path, which must already be normalized: relative, /-separated,
no leading slash and no .. segments.
Sourcepub fn registered() -> Option<&'static EmbeddedAssets>
pub fn registered() -> Option<&'static EmbeddedAssets>
The table linked by #[webx::main(embed)] (or #[webx::embed_assets]),
if any — the same one the host serves, reachable without a Host.
To read a file by path, crate::assets::read is the shorter form.
§Panics
When more than one table is registered — that is always a wiring mistake
(e.g. both #[webx::main(embed)] and a second #[webx::embed_assets]
in the same binary).
Sourcepub fn read(&self, path: &str) -> Option<&'static [u8]>
pub fn read(&self, path: &str) -> Option<&'static [u8]>
The original contents of path, decoded when stored compressed.
path is relative to the embedded root; a leading / is accepted so a
request path works as-is. Verbatim entries are returned without a copy;
compressed ones are decoded on first use and cached for the life of the
process, shared with the middleware. None when the file is not
embedded or its payload fails to decode.
Only the compiled-in copy is read: a same-named file in the disk overlay
and EMBED_ENV play no part.
Sourcepub fn read_str(&self, path: &str) -> Option<&'static str>
pub fn read_str(&self, path: &str) -> Option<&'static str>
read as UTF-8 text; also None when it is not UTF-8.
Sourcepub fn debug_assert_sorted(&self)
pub fn debug_assert_sorted(&self)
Panic in debug builds when the table is not sorted by path, which would
make EmbeddedAssets::get miss entries instead of finding them.
Sourcepub fn shadowed_by(&self, disk_root: &Path) -> Vec<&'static str>
pub fn shadowed_by(&self, disk_root: &Path) -> Vec<&'static str>
Embedded paths for which a same-named file exists under disk_root.
Those are the files an operator is currently overriding. Overrides are the point of the feature, but a stale one silently defeats an updated build, so the host logs them at startup.
Trait Implementations§
Source§impl Clone for EmbeddedAssets
impl Clone for EmbeddedAssets
Source§fn clone(&self) -> EmbeddedAssets
fn clone(&self) -> EmbeddedAssets
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more