firebase_rs_sdk/component/
mod.rs

1mod component;
2pub mod constants;
3pub mod container;
4pub mod provider;
5pub mod types;
6
7pub use component::Component;
8pub use constants::DEFAULT_ENTRY_NAME;
9pub use container::ComponentContainer;
10pub use provider::Provider;
11pub use types::{
12    ComponentError, ComponentType, InstanceFactory, InstanceFactoryOptions, InstantiationMode,
13};
14
15use std::collections::HashMap;
16use std::sync::{Arc, LazyLock, Mutex};
17
18#[cfg(test)]
19mod tests;
20
21static GLOBAL_COMPONENTS: LazyLock<Mutex<HashMap<Arc<str>, Component>>> =
22    LazyLock::new(|| Mutex::new(HashMap::new()));
23
24pub fn global_components() -> &'static Mutex<HashMap<Arc<str>, Component>> {
25    &GLOBAL_COMPONENTS
26}
27
28pub fn register_component(component: Component) -> bool {
29    let mut guard = GLOBAL_COMPONENTS
30        .lock()
31        .unwrap_or_else(|poison| poison.into_inner());
32    if guard.contains_key(component.name()) {
33        return false;
34    }
35    guard.insert(Arc::from(component.name().to_owned()), component);
36    true
37}
38
39#[cfg(test)]
40pub fn clear_global_components_for_test() {
41    GLOBAL_COMPONENTS
42        .lock()
43        .unwrap_or_else(|poison| poison.into_inner())
44        .clear();
45}