Skip to main content

Module cgp

Module cgp 

Source
Expand description

Context-Generic Programming (CGP) core wiring trait.

CGP is a type-level composition pattern where a “context” struct maps component names to concrete provider types. The foundational trait is HasComponent, which performs this mapping. The crate::delegate_components macro generates bulk implementations.

§Compile-time wiring checks (CGP v0.8.0 style)

delegate_components! only records the mapping: it does not prove that the chosen provider actually implements the capability’s provider trait for the context. That mistake otherwise surfaces deep inside a generic consumer bound. crate::delegate_and_check_components and crate::check_components move the failure back to the wiring entry, so add a provider that does not implement its trait is rejected where the choice was made.

§Example

ⓘ
// Define component marker types and a provider trait with an explicit context.
struct ApprovalComponent;
struct SandboxComponent;
trait ApprovalProvider<Ctx> {}
struct PromptApproval;
impl<C> ApprovalProvider<C> for PromptApproval {}

// Wire and verify in one table.
delegate_and_check_components!(InteractiveCtx {
    ApprovalComponent => PromptApproval : ApprovalProvider<InteractiveCtx>,
    SandboxComponent  => WorkspaceSandbox : SandboxProvider<InteractiveCtx>,
});

// Or verify wiring declared elsewhere against the resolved providers.
check_components!(InteractiveCtx {
    ApprovalComponent => ApprovalProvider<InteractiveCtx>,
});

Traits§

HasComponent
Type-level lookup: maps a component Name to a concrete Provider type for a given implementor (the “context”).

Type Aliases§

ComponentProvider
The elaborated provider/dictionary selected by Ctx for component Name.