use std::sync::OnceLock;
use super::provider::SharedScopeProvider;
#[derive(Debug, Clone, Copy)]
pub struct ScopeProviderRegistration {
pub factory: fn() -> SharedScopeProvider,
}
inventory::collect!(ScopeProviderRegistration);
#[must_use]
pub fn discover_scope_providers() -> Vec<SharedScopeProvider> {
inventory::iter::<ScopeProviderRegistration>()
.map(|reg| (reg.factory)())
.collect()
}
#[must_use]
pub fn scope_providers() -> &'static [SharedScopeProvider] {
static PROVIDERS: OnceLock<Vec<SharedScopeProvider>> = OnceLock::new();
PROVIDERS.get_or_init(discover_scope_providers)
}
#[macro_export]
macro_rules! register_scope_provider {
($factory:expr) => {
::inventory::submit! {
$crate::scope::ScopeProviderRegistration {
factory: $factory,
}
}
};
}