Skip to main content

EmbeddedAssets

Struct EmbeddedAssets 

Source
pub struct EmbeddedAssets { /* private fields */ }
Expand description

A build-time directory tree of static files.

Implementations§

Source§

impl EmbeddedAssets

Source

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.

Source

pub const fn root(&self) -> &'static str

The directory the bytes were compiled from, as written by the caller.

Source

pub const fn files(&self) -> &'static [EmbeddedAsset]

The table, sorted by EmbeddedAsset::path.

Source

pub fn len(&self) -> usize

Number of embedded files.

Source

pub fn is_empty(&self) -> bool

Whether the table is empty.

Source

pub fn total_bytes(&self) -> u64

Combined size of the stored payloads, in bytes — what the binary holds.

Source

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.

Source

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.

Source

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).

Source

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.

Source

pub fn read_str(&self, path: &str) -> Option<&'static str>

read as UTF-8 text; also None when it is not UTF-8.

Source

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.

Source

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

Source§

fn clone(&self) -> EmbeddedAssets

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Collect for EmbeddedAssets

Source§

impl Copy for EmbeddedAssets

Source§

impl Debug for EmbeddedAssets

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl From<EmbeddedAssets> for SpaSource

Source§

fn from(assets: EmbeddedAssets) -> SpaSource

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more