pub trait Plugin {
// Required methods
fn build(
&mut self,
ctx: &mut PluginBuildContext<'_>,
) -> Result<(), Box<dyn Error>>;
fn update(
&mut self,
ctx: &mut PluginUpdateContext<'_>,
) -> Result<(), Box<dyn Error>>;
fn name(&self) -> &'static str;
// Provided method
fn shutdown(&mut self) -> Result<(), Box<dyn Error>> { ... }
}Expand description
A trait that all plugins must implement to be inserted into App
§Example
use std::collections::HashMap;
use specs::{DispatcherBuilder, World};
use specs::prelude::{ResourceId, Resource};
use specs::shred::cell::AtomicRefCell;
use std::boxed::Box;
use std::error::Error;
use furmint_runtime::plugins::{Plugin, PluginBuildContext, PluginUpdateContext};
struct MyCoolPlugin;
impl Plugin for MyCoolPlugin {
fn build(
&mut self,
_ctx: &mut PluginBuildContext<'_>
) -> Result<(), Box<dyn Error>> {
// initialize your plugin here
Ok(())
}
fn update(&mut self, _ctx: &mut PluginUpdateContext<'_>) -> Result<(), Box<dyn Error>> {
// update your plugin state
Ok(())
}
fn name(&self) -> &'static str {
"my_cool_plugin"
}
}Required Methods§
Sourcefn build(
&mut self,
ctx: &mut PluginBuildContext<'_>,
) -> Result<(), Box<dyn Error>>
fn build( &mut self, ctx: &mut PluginBuildContext<'_>, ) -> Result<(), Box<dyn Error>>
Prepare/initialize the plugin, return a result of the initialization.
§Arguments
dispatcher_builder: a mutable reference tospecs::DispatcherBuilderso the plugin can register its own systemsworld: a mutable reference toWorldso the plugin can register components, insert resources, e.t.c.