pub struct Source { /* private fields */ }
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
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
Auto Trait Implementations
impl !RefUnwindSafe for Source
impl !UnwindSafe for Source
Blanket Implementations
Mutably borrows from an owned value. Read more