pub trait Component: Any {
// Required methods
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
fn name(&self) -> &'static str;
// Provided methods
fn set_id(&mut self, _component: ComponentId) { ... }
fn init(&mut self, _emit: &mut dyn SignalEmitter, _component: ComponentId) { ... }
fn cleanup(
&mut self,
_emit: &mut dyn SignalEmitter,
_component: ComponentId,
) { ... }
fn encode(&self) -> HashMap<String, Value> { ... }
fn decode(&mut self, _data: &HashMap<String, Value>) -> Result<(), String> { ... }
fn to_mms_ast(&self, _world: &World) -> ComponentExpression { ... }
}Expand description
Component interface.
init runs when the component is registered
Required Methods§
Provided Methods§
fn set_id(&mut self, _component: ComponentId)
Sourcefn init(&mut self, _emit: &mut dyn SignalEmitter, _component: ComponentId)
fn init(&mut self, _emit: &mut dyn SignalEmitter, _component: ComponentId)
Called when component is added to the World
Sourcefn cleanup(&mut self, _emit: &mut dyn SignalEmitter, _component: ComponentId)
fn cleanup(&mut self, _emit: &mut dyn SignalEmitter, _component: ComponentId)
Called when component is removed from the World.
Sourcefn encode(&self) -> HashMap<String, Value>
fn encode(&self) -> HashMap<String, Value>
Encode component data to a HashMap for serialization.
Components should serialize their data fields (not runtime handles).
Sourcefn decode(&mut self, _data: &HashMap<String, Value>) -> Result<(), String>
fn decode(&mut self, _data: &HashMap<String, Value>) -> Result<(), String>
Decode component data from a HashMap after deserialization.
Components should restore their data fields from the map.
Sourcefn to_mms_ast(&self, _world: &World) -> ComponentExpression
fn to_mms_ast(&self, _world: &World) -> ComponentExpression
Encode this component as an MMS Component Expression AST node.
The returned ComponentExpression should round-trip through the
MMS pipeline: unparse → parse → eval_ce → spawn_tree reconstructs
an equivalent component. Default impl emits a bare CE with no
constructors/body, using name() (snake_case) as the type — this
works for “tag” components with no state but most overrides will
want to emit proper builder calls for their fields.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".