Trait EmbedableFile

Source
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§

Source

type Data: 'static + AsRef<[u8]>

Source

type Meta: 'static + AsRef<str>

Required Methods§

Source

fn name(&self) -> Self::Meta

The name of the embedded file.

Source

fn data(&self) -> Self::Data

The contents of the embedded file.

Source

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

Source

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

Source

fn last_modified_timestamp(&self) -> Option<i64>

The UNIX timestamp of when the file was last modified.

Source

fn last_modified(&self) -> Option<Self::Meta>

The rfc2822 encoded last modified date. This is the format you use for Last-Modified headers.

Source

fn hash(&self) -> Self::Meta

The hash value for the file. This is a base85 encoded sha256 hash.

Source

fn etag(&self) -> Self::Meta

The ETag value for the file. This is just the file hash, wrapped with quote symbols.

Source

fn mime_type(&self) -> Option<Self::Meta>

The mime type for the file, if one can be guessed from the file extension.

Implementors§