Expand description
Minimalistic, type-safe ClientHub.
Design goals:
- Providers register an implementation once (local or remote).
- Consumers fetch by interface type (trait object):
get::<dyn my::Api>(). - For plugin-like scenarios, multiple implementations of the same interface can coexist under different scopes (e.g. selected by GTS instance ID).
Implementation details:
- Key = type name. We use
type_name::<T>(), which works forT = dyn Trait. - Value =
Arc<T>stored asBox<dyn Any + Send + Sync>(downcast on read). - Sync hot path:
get()is non-async; no hidden per-entry cells or lazy slots.
Notes:
- Re-registering overwrites the previous value atomically; existing Arcs held by consumers remain valid.
- For testing, just register a mock under the same trait type.
Structs§
- Client
Hub - Type-safe registry of clients keyed by interface type.
- Client
Scope - A scope for resolving multiple implementations of the same interface type.
- TypeKey
- Stable type key for trait objects — uses fully-qualified
type_name::<T>().