pub struct EmbeddedAsset {
pub path: &'static str,
pub bytes: &'static [u8],
pub raw_len: usize,
pub encoding: ContentEncoding,
pub content_type: &'static str,
pub etag: &'static str,
}Expand description
One file compiled into the executable.
Produced by generated code; the fields are public so a build script can emit the same table by hand.
Fields§
§path: &'static strNormalized path relative to the embedded root, /-separated and without
a leading slash (e.g. assets/app.abc123.js). Matched case-sensitively.
bytes: &'static [u8]The stored payload: the file for ContentEncoding::Identity, its
brotli stream for ContentEncoding::Brotli. Placed in the binary’s
read-only data section.
raw_len: usizeLength of the file before compression. Equals bytes.len() when the
payload is stored verbatim.
encoding: ContentEncodingHow bytes is encoded.
content_type: &'static strMedia type resolved at build time, so no runtime extension lookup is needed.
etag: &'static strA strong, quoted ETag derived from the content.
Embedded files have no mtime, so this is the only validator they can
offer. Because it hashes the bytes it is also stable across machines and
rebuilds, unlike the host’s size-mtime tag for files on disk.
Implementations§
Source§impl EmbeddedAsset
impl EmbeddedAsset
Sourcepub fn decode(&self) -> Option<Vec<u8>>
pub fn decode(&self) -> Option<Vec<u8>>
Decode the stored payload back to the original file.
None only when an encoded payload fails to decode, which means the
table is corrupt; the caller still has bytes to serve.
Sourcepub fn is_encoded(&self) -> bool
pub fn is_encoded(&self) -> bool
Whether the payload is stored compressed.
Sourcepub fn etag_for(&self, encoded: bool) -> String
pub fn etag_for(&self, encoded: bool) -> String
The strong validator for one representation of this asset.
A compressed payload is a different representation, so it needs its own
ETag: reusing the identity tag would let a shared cache hand brotli
bytes to a client that asked for the plain file.
Trait Implementations§
Source§impl Clone for EmbeddedAsset
impl Clone for EmbeddedAsset
Source§fn clone(&self) -> EmbeddedAsset
fn clone(&self) -> EmbeddedAsset
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more