1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//! 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
//!
//! ```rust,ignore
//! // 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>,
//! });
//! ```
/// Type-level lookup: maps a component **Name** to a concrete **Provider**
/// type for a given implementor (the "context").
///
/// This is the single foundational trait of the CGP substrate. All
/// composition flows through it.
/// The elaborated provider/dictionary selected by `Ctx` for component `Name`.
pub type ComponentProvider<Ctx, Name> = Provider;
/// Wire multiple component names to provider types for a context.
///
/// Generates one `HasComponent<Name>` implementation per entry.
///
/// ```rust,ignore
/// delegate_components!(MyCtx {
/// ApprovalComponent => PromptApproval,
/// SandboxComponent => WorkspaceSandbox,
/// });
/// ```
/// Wire components and prove each provider implements its capability trait.
///
/// Each entry is `Component => Provider : ProviderTrait<Ctx>`. The trait check
/// is type-checked at the table entry, so a mis-wiring is reported next to the
/// choice rather than in the consumer bound that later needs the capability.
///
/// ```rust,ignore
/// delegate_and_check_components!(InteractiveCtx {
/// ApprovalComponent => PromptApproval : ApprovalProvider<InteractiveCtx>,
/// SandboxComponent => WorkspaceSandbox : SandboxProvider<InteractiveCtx>,
/// });
/// ```
/// Verify the providers already wired for a concrete context.
///
/// Unlike [`crate::delegate_and_check_components`], this checks the resolved
/// [`crate::cgp::ComponentProvider`] instead of a provider written at the call
/// site, so it can validate a context whose wiring lives in another module.
///
/// ```rust,ignore
/// check_components!(InteractiveCtx {
/// ApprovalComponent => ApprovalProvider<InteractiveCtx>,
/// SandboxComponent => SandboxProvider<InteractiveCtx>,
/// });
/// ```