Macro aframe::component_struct
source · macro_rules! component_struct { ($(#[$outer:meta])* $name:ident $(, $field:ident: $field_name:literal $ty:ty = $default:expr)*) => { ... }; ($(#[$outer:meta])* $name:ident $(:$alt:ident)? $fmt:expr $(, $field:ident: $field_name:literal $ty:ty = $default:expr)*) => { ... }; }
Expand description
While component_def!
creates a component that Aframe can access from its
own runtime, the component_struct!
macro creates a Rust struct that mimics
the internal details of that Aframe component. Component structs are already
provided for Aframe’s built-in components (WIP: not all components are defined
yet. Once all aframe components are defined, calling component_struct!
should only be necessary for locally-defined components. Once all components
from Aframe have been defined, component_def!
and component_struct!
may
be merged into a single macro to do the heavy-lifting of both at once). The
component must be already registered in aframe before this struct may be used
(although constructing it before that is safe). There are 2 variation of
syntax provided, depending on the desired resulting Display
implementation.
use aframe::component_struct;
// Example 1, uses hard-coded display implementation:
component_struct!
{
/// Doc comment for StructName
StructName,
field_1: "field1Name" f32 = 1.5,
field_2: "field2Name" bool = false
}
// This will display as: "field1Name: 1.5; field2Name: false"
// Example 2, uses custom display implementation:
component_struct!{Vec3 "{} {} {}",
x: f32 = 1.0,
y: f32 = 1.5,
z: f32 = 2.0
}
// This will display as "1.0 1.5 2.0"
When using items defined with this macro or with the complex_enum!
macro
as fields, a custom display implementation may be used to flatten out the
nested properties and print correctly as a single semicolon-separated list
of properties.