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"); }
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.
Auto Trait Implementations
impl<'a> RefUnwindSafe for Metadata<'a>
impl<'a> UnwindSafe for Metadata<'a>
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
pub fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
pub fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
Converts self
into a collection.
pub fn vzip(self) -> V