nexus-rt 2.0.3

Single-threaded, event-driven runtime primitives with pre-resolved dispatch
Documentation
//! Plugin trait for composable resource registration.

use crate::world::WorldBuilder;

/// Composable unit of resource registration.
///
/// Analogous to Bevy's `Plugin`.
///
/// Plugins register resources into a [`WorldBuilder`]. The runtime is
/// assembled by installing plugins via [`WorldBuilder::install_plugin`].
///
/// # Examples
///
/// ```ignore
/// struct TradingPlugin;
///
/// impl Plugin for TradingPlugin {
///     fn build(self, world: &mut WorldBuilder) {
///         world.register(PriceCache::new());
///         world.register(TradeState::default());
///     }
/// }
///
/// let mut wb = WorldBuilder::new();
/// wb.install_plugin(TradingPlugin);
/// ```
pub trait Plugin {
    /// Register resources into the world.
    fn build(self, world: &mut WorldBuilder);
}

impl<F: FnOnce(&mut WorldBuilder)> Plugin for F {
    fn build(self, world: &mut WorldBuilder) {
        self(world);
    }
}