pub struct Runtime {
engine: Engine,
linker: Linker<WidgetState>,
last_run: HashMap<String, Datetime>,
}Fields§
§engine: Engine§linker: Linker<WidgetState>§last_run: HashMap<String, Datetime>Implementations§
Source§impl Runtime
impl Runtime
Sourceunsafe fn load_module(&self, bytes: &[u8]) -> Result<Component>
unsafe fn load_module(&self, bytes: &[u8]) -> Result<Component>
Deserialises a precompiled Wasmtime component from raw bytes.
Sourcefn instantiate(
&mut self,
component: &Component,
store: &mut Store<WidgetState>,
) -> Result<Widget>
fn instantiate( &mut self, component: &Component, store: &mut Store<WidgetState>, ) -> Result<Widget>
Binds host functions and instantiates a loaded component. Requires a mutable store, any created store should only live as long as it is needed and should be destroyed after widget executution to free up memory.
Sourcefn run(
&mut self,
widget: &Widget,
config: String,
store: &mut Store<WidgetState>,
name: String,
) -> Result<Option<WidgetResult>>
fn run( &mut self, widget: &Widget, config: String, store: &mut Store<WidgetState>, name: String, ) -> Result<Option<WidgetResult>>
Calls the widget’s run export with the given JSON config string.
Passes a WidgetContext containing the last-invocation timestamp and
the widget’s current config. Returns the WidgetResult containing the
text to display on screen.
Pass the same store as the one passed to Self::instantiate, otherwise the execution will fail.
Sourcefn get_widget_name(
&mut self,
widget: &Widget,
store: &mut Store<WidgetState>,
) -> Result<String>
fn get_widget_name( &mut self, widget: &Widget, store: &mut Store<WidgetState>, ) -> Result<String>
Returns the widget’s display name (calls get-name WIT export).
Sourcefn get_config_schema(
&mut self,
widget: &Widget,
store: &mut Store<WidgetState>,
) -> Result<String>
fn get_config_schema( &mut self, widget: &Widget, store: &mut Store<WidgetState>, ) -> Result<String>
Returns the widget’s JSON Schema config string (calls get-config-schema WIT export).
Sourcefn get_widget_version(
&mut self,
widget: &Widget,
store: &mut Store<WidgetState>,
) -> Result<String>
fn get_widget_version( &mut self, widget: &Widget, store: &mut Store<WidgetState>, ) -> Result<String>
Returns the widget’s semver version string (calls get-version WIT export).
Sourcefn get_run_update_cycle_seconds(
&mut self,
widget: &Widget,
store: &mut Store<WidgetState>,
) -> Result<u32>
fn get_run_update_cycle_seconds( &mut self, widget: &Widget, store: &mut Store<WidgetState>, ) -> Result<u32>
Returns how often the widget should be run in seconds (calls get-run-update-cycle-seconds).
Sourcepub async unsafe fn run_widget(
&mut self,
widget_name: String,
config: String,
) -> Result<Option<WidgetResult>>
pub async unsafe fn run_widget( &mut self, widget_name: String, config: String, ) -> Result<Option<WidgetResult>>
Wrapper function for running a widget by name with given json config
Sourcepub async unsafe fn get_widget_metadata(
&mut self,
bytes: &[u8],
) -> Result<WidgetInstallationData>
pub async unsafe fn get_widget_metadata( &mut self, bytes: &[u8], ) -> Result<WidgetInstallationData>
wrapper function to get all widget metadata with the same store
Sets the [WidgetInstallationData::json_config] to {}, until the widget gets configured via the UI.