tessera_ui/
entry_registry.rs1use 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
11pub trait TesseraPackage {
13 fn register(self, registry: &mut EntryRegistry);
15}
16
17pub struct EntryRegistry {
19 modules: Vec<Box<dyn RenderModule>>,
20}
21
22impl EntryRegistry {
23 pub fn new() -> Self {
25 Self {
26 modules: Vec::new(),
27 }
28 }
29
30 pub fn add_module(&mut self, module: impl RenderModule + 'static) {
32 self.modules.push(Box::new(module));
33 }
34
35 pub fn register_plugin<P: Plugin>(&mut self, plugin: P) {
37 register_plugin(plugin);
38 }
39
40 pub fn register_plugin_boxed<P: Plugin>(&mut self, plugin: Arc<RwLock<P>>) {
42 register_plugin_boxed(plugin);
43 }
44
45 pub fn register_package<P: TesseraPackage>(&mut self, package: P) {
47 package.register(self);
48 }
49
50 pub fn finish(self) -> Vec<Box<dyn RenderModule>> {
52 self.modules
53 }
54}
55
56impl Default for EntryRegistry {
57 fn default() -> Self {
58 Self::new()
59 }
60}