pub trait ComponentLoader: Send + Sync {
// Required method
fn load_from_script(
&self,
script: &str,
id: Option<&str>,
globals: Option<&Map<String, Value>>,
) -> Result<Box<dyn Component>, SpawnError>;
// Provided method
fn resolve_builtin(&self, _name: &str) -> Option<String> { ... }
}Expand description
Loader for creating Components from scripts.
This trait allows runtime implementations to create Components without depending on specific implementations (e.g., LuaComponent).
Required Methods§
Sourcefn load_from_script(
&self,
script: &str,
id: Option<&str>,
globals: Option<&Map<String, Value>>,
) -> Result<Box<dyn Component>, SpawnError>
fn load_from_script( &self, script: &str, id: Option<&str>, globals: Option<&Map<String, Value>>, ) -> Result<Box<dyn Component>, SpawnError>
Creates a Component from inline script content.
§Arguments
-
script- Inline script content -
id- Optional component ID (extracted from script if None) -
globals- Optional key-value pairs to inject into the VM before script execution. Each entry becomes a global variable in the new VM, enabling structured data passing without string-based code injection.The type is
Map<String, Value>(a JSON object) rather than a genericserde_json::Valueso that the compiler enforces the “must be an object” invariant at the call site. This follows the parse, don’t validate principle — callers convert toMaponce, and downstream code never needs to re-check or useunreachable!()branches.
§Returns
A boxed Component, or an error if loading failed.