pub struct SchemaRegistry { /* private fields */ }Expand description
Registry of metric and event schema metadata linked into the current binary.
global lazily discovers every spectra_schema! and spectra_metric!
registration submitted through inventory. Schema modules must be compiled into the binary
(linked with mod); declaring macros alone in unlinked files does not register them.
§Examples
use spectra_core::SchemaRegistry;
let registry = SchemaRegistry::global();
for name in registry.list_schemas() {
let schema = registry.get_schema(name).expect("listed schema");
println!("{} uses store {}", schema.table_name(), schema.store);
}
// "default" is always available even when this binary declares no schemas.
assert!(registry.distinct_store_names().iter().any(|name| name == "default"));Implementations§
Source§impl SchemaRegistry
impl SchemaRegistry
Sourcepub fn new() -> SchemaRegistry
pub fn new() -> SchemaRegistry
Creates an empty registry.
Sourcepub fn auto_discover() -> SchemaRegistry
pub fn auto_discover() -> SchemaRegistry
Populate from all inventory::submit!-ed SchemaMetadataInit items.
Sourcepub fn set_global(registry: SchemaRegistry)
pub fn set_global(registry: SchemaRegistry)
Installs a custom registry as the process-global instance (call once).
Sourcepub fn global() -> &'static SchemaRegistry
pub fn global() -> &'static SchemaRegistry
Returns the process-global registry, auto-discovering on first access.
Sourcepub fn register(&mut self, metadata: &'static SchemaMetadata)
pub fn register(&mut self, metadata: &'static SchemaMetadata)
Registers a leaked schema metadata entry.
Sourcepub fn get_schema(
&self,
table_or_metric: &str,
) -> Option<&'static SchemaMetadata>
pub fn get_schema( &self, table_or_metric: &str, ) -> Option<&'static SchemaMetadata>
Looks up schema metadata by table or metric name.
Sourcepub fn list_schemas(&self) -> Vec<&str>
pub fn list_schemas(&self) -> Vec<&str>
Lists all registered table and metric names.
Sourcepub fn has_schema(&self, table_or_metric: &str) -> bool
pub fn has_schema(&self, table_or_metric: &str) -> bool
Returns whether a schema is registered.
Sourcepub fn distinct_store_names(&self) -> Vec<String>
pub fn distinct_store_names(&self) -> Vec<String>
Distinct store names from all registered schemas, always including "default".
Methods from Deref<Target = Registry<SchemaMetadata>>§
Sourcepub fn get(&self, key: &str) -> Option<&'static T>
pub fn get(&self, key: &str) -> Option<&'static T>
Look up an item by registry key.
Sourcepub fn iter(&self) -> impl Iterator<Item = &'static T>
pub fn iter(&self) -> impl Iterator<Item = &'static T>
Iterates over all registered descriptors in arbitrary order.