Skip to main content

Plugin

Trait Plugin 

Source
pub trait Plugin {
    // Required methods
    fn prepare(
        &mut self,
        dependencies: HashMap<String, &AtomicRefCell<Box<dyn Resource>>>,
    ) -> Result<()>;
    fn update(&mut self, delta_time: f64) -> Result<()>;
    fn resource_dependencies(&mut self) -> HashMap<String, ResourceId>;
    fn name(&self) -> &'static str;
}
Expand description

A trait that all plugins must implement in order to be inserted into App

§Example

use specs::World;
use fennel_plugins::Plugin;
struct MyCoolPlugin;

impl Plugin for MyCoolPlugin {
	fn prepare(&mut self, _world: *mut World) -> anyhow::Result<()> {
 		// initialize your plugin here
   		Ok(())
   	}

 	fn update(&mut self, delta_time: f64) -> anyhow::Result<()> {
		// update your plugin state
		Ok(())
	}

	fn name(&self) -> &'static str {
   		"my_cool_plugin"
	}
}

Required Methods§

Source

fn prepare( &mut self, dependencies: HashMap<String, &AtomicRefCell<Box<dyn Resource>>>, ) -> Result<()>

Prepare/initialize the plugin, return a result of this

Source

fn update(&mut self, delta_time: f64) -> Result<()>

Update the plugin state, return a result of this

Source

fn resource_dependencies(&mut self) -> HashMap<String, ResourceId>

Return a list of your resource dependencies here or an empty Vec if you don’t need any resources. Use the ResourceId::new function to acquire a ResourceId instance.

Usually you want the dependency to be an [Arc], [Rc] or some sort of channel receiver/sender, as under the hood fennel_engine clones the resource.

Source

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

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

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§