pub trait Template {
type Output;
// Required methods
fn build_template(
&self,
context: &mut TemplateContext<'_, '_>,
) -> Result<Self::Output>;
fn clone_template(&self) -> Self;
}Expand description
A Template is something that, given a spawn context (target Entity, World, etc), can produce a Template::Output.
Template is the cornerstone of scene systems. It enables define types (and hierarchies) that require no World or Entity context to define,
but can use that context to produce the final runtime state. A Template is notably:
- Repeatable: Building a
Templatedoes not consume it. This enables reusing “baked” scenes / avoids rebuilding scenes each time we want to spawn one. - Clone-able: Templates can be duplicated via
Template::clone_template, enabling scenes to be duplicated, supporting copy-on-write behaviors, etc. - (Often) Serializable: Templates are intended to be easily serialized and deserialized, as they are typically composed of raw data.
Asset handles and Entity are two commonly Template-ed types. Asset handles are often “loaded” from an “asset path”. The “asset path” would be the Template.
Likewise Entity on its own has no reasonable default. A type with an Entity reference could use an “entity path” template to point to a specific entity, relative
to the current spawn context.
See FromTemplate, which defines the canonical Template for a type. This can be derived, which will generate a Template for the deriving type.
Required Associated Types§
Required Methods§
Sourcefn build_template(
&self,
context: &mut TemplateContext<'_, '_>,
) -> Result<Self::Output>
fn build_template( &self, context: &mut TemplateContext<'_, '_>, ) -> Result<Self::Output>
Uses this template and the given entity context to produce a Template::Output.
Sourcefn clone_template(&self) -> Self
fn clone_template(&self) -> Self
Clones this template. See Clone.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.