Skip to main content

tessera_ui/
entry_registry.rs

1//! Entry package registry for renderer startup.
2use std::sync::Arc;
3
4use parking_lot::RwLock;
5
6use crate::{
7    plugin::{Plugin, register_plugin, register_plugin_boxed},
8    render_module::RenderModule,
9};
10
11/// Registers modules and plugins for a Tessera entry point.
12pub trait TesseraPackage {
13    /// Registers this package into the provided registry.
14    fn register(self, registry: &mut EntryRegistry);
15}
16
17/// Collects modules and registers plugins for an application entry.
18#[derive(Default)]
19pub struct EntryRegistry {
20    modules: Vec<Box<dyn RenderModule>>,
21}
22
23impl EntryRegistry {
24    /// Creates a new registry for entry-time registration.
25    pub fn new() -> Self {
26        Self::default()
27    }
28
29    /// Adds a render module to the entry registry.
30    pub fn add_module(&mut self, module: impl RenderModule + 'static) {
31        self.modules.push(Box::new(module));
32    }
33
34    /// Registers a plugin instance with the application session.
35    pub fn register_plugin<P: Plugin>(&mut self, plugin: P) {
36        register_plugin(plugin);
37    }
38
39    /// Registers a boxed plugin instance with the application session.
40    pub fn register_plugin_boxed<P: Plugin>(&mut self, plugin: Arc<RwLock<P>>) {
41        register_plugin_boxed(plugin);
42    }
43
44    /// Registers a package into the entry registry.
45    pub fn register_package<P: TesseraPackage>(&mut self, package: P) {
46        package.register(self);
47    }
48
49    /// Finalizes the registry into a module list for the renderer.
50    pub fn finish(self) -> Vec<Box<dyn RenderModule>> {
51        self.modules
52    }
53}