logo
pub struct Source { /* private fields */ }
This is supported on crate feature source only.
Expand description

Utility for dynamic template loading.

Because an Environment holds a reference to the source lifetime it borrows templates from, it becomes very inconvenient when it is shared. This object provides a solution for such cases. First templates are loaded into the source, then it can be set as the “source” for an environment decouping the lifetimes. Note that once a source has been added to an environment methods such as Environment::add_template must no longer be used as otherwise the same lifetime concern arises.

Example

fn create_env() -> Environment<'static> {
    let mut env = Environment::new();
    let mut source = Source::new();
    source.load_from_path("templates", &["html"]).unwrap();
    env.set_source(source);
    env
}

Implementations

Creates an empty source.

Adds a new template into the source.

This is similar to the method of the same name on the environment but the source is held within the Source object for you. This means that lifetimes are not a concern.

Removes an already loaded template from the source.

Loads templates from a path.

This function takes two arguments: path which is the path to where the templates are stored and extensions which is a list of file extensions that should be considered to be templates. Hidden files are always ignored.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.