Struct rocket_dyn_templates::Metadata[][src]

pub struct Metadata<'a>(_);
Expand description

Request guard for dynamically querying template metadata.

Usage

The Metadata type implements Rocket’s FromRequest trait, so it can be used as a request guard in any request handler.

use rocket_dyn_templates::{Template, Metadata};

#[get("/")]
fn homepage(metadata: Metadata) -> Template {
    // Conditionally render a template if it's available.
    if metadata.contains_template("some-template") {
        Template::render("some-template", &context)
    } else {
        Template::render("fallback", &context)
    }
}

fn main() {
    rocket::build()
        .attach(Template::fairing())
        // ...
}

Implementations

Returns true if the template with the given name is currently loaded. Otherwise, returns false.

Example

use rocket_dyn_templates::Metadata;

#[get("/")]
fn handler(metadata: Metadata) {
    // Returns `true` if the template with name `"name"` was loaded.
    let loaded = metadata.contains_template("name");
}

Returns true if template reloading is enabled.

Example

use rocket_dyn_templates::Metadata;

#[get("/")]
fn handler(metadata: Metadata) {
    // Returns `true` if template reloading is enabled.
    let reloading = metadata.reloading();
}

Trait Implementations

Retrieves the template metadata. If a template fairing hasn’t been attached, an error is printed and an empty Err with status InternalServerError (500) is returned.

The associated error to be returned if derivation fails.

Derives an instance of Self from the incoming request metadata. Read more

Returns true if launch should be aborted and false otherwise.

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.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Converts self into a collection.

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.