wasm-capability-core 0.2.0

This pattern's own default, zero-external-technology implementation: InMemoryCapabilityRegistry (SEA core/, local ADR-001).
Documentation
//! [`InMemoryCapabilityRegistry`] — concrete, data-assembled `CapabilityRegistry`,
//! built on `svc-registry-adapter`'s real `DefaultRegistry<T: Named>` rather
//! than hand-rolled storage.

use svc_registry::Registry;
use svc_registry_adapter::DefaultRegistry;
use wasm_capability_contract::{CapabilityDescriptor, CapabilityRegistry};

use super::in_memory_named_capability_descriptor::InMemoryNamedCapabilityDescriptor;

/// In-memory `CapabilityRegistry` — starts empty, matching
/// `HashMap::new()`/`Vec::new()` convention. This crate has no knowledge
/// of, or dependency on, any specific technology or consumer; a caller
/// registers whichever named instances it needs (e.g.
/// `grpc-egress:inventory-svc`) via [`Self::register`].
pub struct InMemoryCapabilityRegistry {
    entries: DefaultRegistry<InMemoryNamedCapabilityDescriptor>,
}

impl InMemoryCapabilityRegistry {
    /// Constructs an empty registry with no pre-registered entries.
    #[must_use]
    pub fn new() -> Self {
        Self {
            entries: DefaultRegistry::default(),
        }
    }

    /// Registers `descriptor` under `name`, replacing any existing entry
    /// with the same name. Fluent — chainable to build up a registry one
    /// entry at a time.
    #[must_use]
    pub fn register(mut self, name: impl Into<String>, descriptor: CapabilityDescriptor) -> Self {
        self.entries.register(InMemoryNamedCapabilityDescriptor {
            key: name.into(),
            descriptor,
        });
        self
    }
}

impl Default for InMemoryCapabilityRegistry {
    fn default() -> Self {
        Self::new()
    }
}

impl CapabilityRegistry for InMemoryCapabilityRegistry {
    fn descriptor(&self, capability: &str) -> Option<&CapabilityDescriptor> {
        self.entries.get(capability).map(|entry| &entry.descriptor)
    }
}