pub struct Widget {
get_config_schema: Func,
get_name: Func,
get_run_update_cycle_seconds: Func,
get_version: Func,
run: Func,
}Expand description
Auto-generated bindings for an instance a component which
implements the world widget.
This structure can be created through a number of means depending on your requirements and what you have on hand:
-
The most convenient way is to use
Widget::instantiatewhich only needs aStore,Component, andLinker. -
Alternatively you can create a
WidgetPreahead of time with aComponentto front-load string lookups of exports once instead of per-instantiation. This method then usesWidgetPre::instantiateto create aWidget. -
If you’ve instantiated the instance yourself already then you can use
Widget::new.
These methods are all equivalent to one another and move around the tradeoff of what work is performed when.
Fields§
§get_config_schema: Func§get_name: Func§get_run_update_cycle_seconds: Func§get_version: Func§run: FuncImplementations§
Source§impl Widget
impl Widget
Sourcepub fn instantiate<_T>(
store: impl AsContextMut<Data = _T>,
component: &Component,
linker: &Linker<_T>,
) -> Result<Widget>
pub fn instantiate<_T>( store: impl AsContextMut<Data = _T>, component: &Component, linker: &Linker<_T>, ) -> Result<Widget>
Convenience wrapper around WidgetPre::new and
WidgetPre::instantiate.
Sourcepub fn new(store: impl AsContextMut, instance: &Instance) -> Result<Widget>
pub fn new(store: impl AsContextMut, instance: &Instance) -> Result<Widget>
Convenience wrapper around WidgetIndices::new and
WidgetIndices::load.
pub fn add_to_linker<T, D>(
linker: &mut Linker<T>,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> Result<()>where
D: HostWithStore + HostWithStore + HostWithStore + HostWithStore + HostWithStore,
for<'a> D::Data<'a>: Host + Host + Host + Host + Host,
T: 'static,
Sourcepub fn call_get_name<S: AsContextMut>(&self, store: S) -> Result<String>
pub fn call_get_name<S: AsContextMut>(&self, store: S) -> Result<String>
Return the name of the widget
Sourcepub fn call_get_version<S: AsContextMut>(&self, store: S) -> Result<String>
pub fn call_get_version<S: AsContextMut>(&self, store: S) -> Result<String>
Return the semantic version of the widget
Sourcepub fn call_get_config_schema<S: AsContextMut>(
&self,
store: S,
) -> Result<String>
pub fn call_get_config_schema<S: AsContextMut>( &self, store: S, ) -> Result<String>
Return the config JSON schema string
Sourcepub fn call_get_run_update_cycle_seconds<S: AsContextMut>(
&self,
store: S,
) -> Result<u32>
pub fn call_get_run_update_cycle_seconds<S: AsContextMut>( &self, store: S, ) -> Result<u32>
Returns the run update cycle in seconds. With this, widgets can control how frequently they shall be updated.
Sourcepub fn call_run<S: AsContextMut>(
&self,
store: S,
arg0: &WidgetContext,
) -> Result<WidgetResult>
pub fn call_run<S: AsContextMut>( &self, store: S, arg0: &WidgetContext, ) -> Result<WidgetResult>
Invoke the widget with the given context