Expand description
HubContext - generic parent context injection for hub-aware plugins
This module defines the HubContext trait that allows plugins to receive
typed context from their parent hub. The pattern enables:
- Symmetric context passing: every hub passes something to its children
- Generic plugins:
Plugin<P: HubContext>works with any parent type - Type safety: children know what capabilities their parent provides
§Example
ⓘ
// A plugin generic over its parent context
pub struct Cone<P: HubContext> {
parent: Arc<OnceLock<P>>,
storage: Arc<ConeStorage>,
}
impl<P: HubContext> Cone<P> {
pub fn inject_parent(&self, parent: P) {
let _ = self.parent.set(parent);
}
async fn resolve_foreign_handle(&self, handle: &Handle) -> Option<Value> {
self.parent.get()?.resolve_handle(handle).await
}
}
// Plexus injects itself (as Weak<Plexus>)
let cone: Cone<Weak<Plexus>> = Cone::new();
cone.inject_parent(Arc::downgrade(&plexus));
// A sub-hub could inject its own context
let widget: Widget<DashboardContext> = Widget::new();
widget.inject_parent(dashboard_ctx);Structs§
- NoParent
- A no-op context for plugins that don’t need parent access.
Traits§
- HubContext
- Trait for parent context that can be injected into child plugins.
- Parent
Aware - Marker trait for plugins that accept parent context injection.