Skip to main content

nexus_rt/
plugin.rs

1//! Plugin trait for composable resource registration.
2
3use crate::world::WorldBuilder;
4
5/// Composable unit of resource registration.
6///
7/// Analogous to Bevy's `Plugin`.
8///
9/// Plugins register resources into a [`WorldBuilder`]. The runtime is
10/// assembled by installing plugins via [`WorldBuilder::install_plugin`].
11///
12/// # Examples
13///
14/// ```ignore
15/// struct TradingPlugin;
16///
17/// impl Plugin for TradingPlugin {
18///     fn build(self, world: &mut WorldBuilder) {
19///         world.register(PriceCache::new());
20///         world.register(TradeState::default());
21///     }
22/// }
23///
24/// let mut wb = WorldBuilder::new();
25/// wb.install_plugin(TradingPlugin);
26/// ```
27pub trait Plugin {
28    /// Register resources into the world.
29    fn build(self, world: &mut WorldBuilder);
30}
31
32impl<F: FnOnce(&mut WorldBuilder)> Plugin for F {
33    fn build(self, world: &mut WorldBuilder) {
34        self(world);
35    }
36}