Skip to main content

Plugin

Trait Plugin 

Source
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§

Source

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 to specs::DispatcherBuilder so the plugin can register its own systems
  • world: a mutable reference to World so the plugin can register components, insert resources, e.t.c.
Source

fn update( &mut self, ctx: &mut PluginUpdateContext<'_>, ) -> Result<(), Box<dyn Error>>

Update the plugin state, return a result of this

Source

fn name(&self) -> &'static str

Return the plugin’s name; must be unique and not change

Provided Methods§

Source

fn shutdown(&mut self) -> Result<(), Box<dyn Error>>

Shutdown the plugin on exit

Implementors§