pub trait EmbedableFile {
type Data: 'static + AsRef<[u8]>;
type Meta: 'static + AsRef<str>;
// Required methods
fn name(&self) -> Self::Meta;
fn data(&self) -> Self::Data;
fn data_gzip(&self) -> Option<Self::Data>;
fn data_br(&self) -> Option<Self::Data>;
fn last_modified_timestamp(&self) -> Option<i64>;
fn last_modified(&self) -> Option<Self::Meta>;
fn hash(&self) -> Self::Meta;
fn etag(&self) -> Self::Meta;
fn mime_type(&self) -> Option<Self::Meta>;
}
Expand description
An embedable file.
The file is embedded into the program for release builds, and dynamically read for debug builds. This trait allows common access for both types.
There are associated types for each file which you can get with
EmbeddedFile::Data
/EmbeddedFile::Meta
or
DynamicFile::Data
/DynamicFile::Meta
. The data of the file depends on
this associated types because embedded files use static types while dynamic
files have to use owned types.
You can access the data by calling the as_ref
function through the AsRef
trait. For example:
fn print_hash<T: EmbedableFile>(file: T) {
println!("The file hash is {}", file.hash().as_ref());
}
Required Associated Types§
Required Methods§
Sourcefn data_gzip(&self) -> Option<Self::Data>
fn data_gzip(&self) -> Option<Self::Data>
The contents of the file, compressed with gzip.
This is Some
if precompression has been done. None
if the file was
not precompressed, either because the file doesn’t benefit from
compression or because gzip was disabled with #[gzip = false]
.
Sourcefn data_br(&self) -> Option<Self::Data>
fn data_br(&self) -> Option<Self::Data>
The contents of the file, compressed with brotli.
This is Some
if precompression has been done. None
if the file was
not precompressed, either because the file doesn’t benefit from
compression or because gzip was disabled with #[br = false]
.
Sourcefn last_modified_timestamp(&self) -> Option<i64>
fn last_modified_timestamp(&self) -> Option<i64>
The UNIX timestamp of when the file was last modified.
Sourcefn last_modified(&self) -> Option<Self::Meta>
fn last_modified(&self) -> Option<Self::Meta>
The rfc2822 encoded last modified date. This is the format you use for
Last-Modified
headers.
Sourcefn hash(&self) -> Self::Meta
fn hash(&self) -> Self::Meta
The hash value for the file. This is a base85 encoded sha256 hash.