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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
//! Capability system for extensions.
//!
//! This module defines the type-safe capability resolution infrastructure.
//! Extensions register capabilities via [`ExtensionCapabilities`], and
//! node factories consume them via [`registry::Capabilities`].
//!
//! Capability traits are defined per-capability in submodules grouped by domain
//! (e.g., `auth::bearer_token_provider`), with local (!Send) and shared
//! (Send + Sync) variants re-exported from
//! [`local::capability`](crate::local::capability) and
//! [`shared::capability`](crate::shared::capability).
// Capability code is organized so every public item has exactly **one** export
// surface -- no item is reachable via two paths:
//
// - A capability's **data types and registration handle** are exposed only on
// the **scoped** surface under its domain. Types shared across a domain's
// capabilities are re-exported at the domain root, `capability::<domain>`
// (e.g. `capability::auth::BearerToken`); a capability's own handle and
// capability-specific types live in its submodule, `capability::<domain>::<name>`
// (e.g. `capability::auth::bearer_token_provider::{BearerTokenProvider,
// TokenStream}`). Their defining modules stay private, so each item has a
// single public path.
//
// - A capability's **trait variants** (the `local` `!Send` / `shared`
// `Send + Sync` traits the `#[capability]` macro generates) are exposed only on the
// **execution-model** surface, `{local,shared}::capability::<domain>::<name>` --
// the surface extensions implement against, alongside `{local,shared}::extension`,
// etc.
//
// The two surfaces don't overlap because the `#[capability]` macro emits its
// `local`/`shared` trait modules as `pub(crate)` (an implementation detail), so
// they are never a public path under `capability::<domain>::<name>`; the traits
// become public only through the hand-written `{local,shared}::capability`
// re-exports.
//
// - Genuinely **shared** framework infrastructure -- used across capabilities
// rather than owned by one -- is re-exported flat at `capability::` (below): the
// error types (`error`), the instance-factory types (`factory`), and the
// `ExtensionCapability` trait plus `KNOWN_CAPABILITIES` (defined in this
// module). These are unique, collision-free vocabulary where a single short
// canonical path is worth more than namespacing. `registry` stays `pub`
// because `registry::Capabilities` is not re-exported at the root.
pub
pub
pub use ;
pub use ;
// -- Sealed ExtensionCapability trait -----------------------------------------
/// Sealing module -- prevents external crates from implementing
/// [`ExtensionCapability`].
/// Compile-time-sealed trait binding a capability registration struct
/// to its local and shared trait object types.
///
/// Each capability (e.g., `BearerTokenProvider`) has a zero-sized
/// registration struct that implements this trait. The associated types
/// tell [`Capabilities::require_local`](registry::Capabilities::require_local)
/// and [`Capabilities::require_shared`](registry::Capabilities::require_shared)
/// which concrete `dyn Trait` to downcast to.
///
/// This trait is sealed -- only the engine crate (via the
/// `#[capability]` proc macro or manual impls) can add new
/// capabilities.
/// Re-export for use by the `#[capability]` proc macro's generated code.
/// `pub(crate)` (not `pub`) preserves the seal: the macro only expands
/// inside this crate, so external crates still can't reach `Sealed` to
/// forge an `ExtensionCapability` impl.
pub use Sealed as CapabilitySealed;
// -- KNOWN_CAPABILITIES (link-time registration) ------------------------------
/// A link-time-registered capability descriptor.
///
/// Each `#[capability]` invocation produces a static entry in the
/// [`KNOWN_CAPABILITIES`] distributed slice. The engine uses this at
/// config validation time to map string names to `TypeId`s.
/// Link-time registry of all capabilities defined in the binary.
///
/// Populated by `#[capability]` proc macro entries. Used by
/// `resolve_bindings()` to validate capability names and retrieve
/// `TypeId`s.
//
// `linkme::distributed_slice` requires a `pub static`; `#[doc(hidden)]`
// excludes it from generated rustdoc so external crates don't see it in
// the public API surface.
pub static KNOWN_CAPABILITIES: = ;
// -- ExtensionCapabilities (factory metadata) ---------------------------------
/// Static metadata describing which capabilities an extension factory provides.
///
/// Carried on [`ExtensionFactory`](crate::ExtensionFactory) and used by:
/// - Config validation: checking that capability bindings reference
/// capabilities the extension actually provides.
/// - `resolve_bindings()`: knowing which registry slots to populate.
///
/// Constructed via the `extension_capabilities!` macro.
///
/// The `register_shared` / `register_local` fn pointers are the bridge
/// between the extension's type-erased instance factories and the
/// capability registry. The engine invokes them at bundle-registration
/// time, passing the extension's `ExtensionId` plus a clone of the
/// appropriate `*InstanceFactory`. The fn pointer internally builds one
/// [`SharedCapabilityEntry`](registry::SharedCapabilityEntry) per
/// listed capability and inserts it into the registry.
///
/// Returns [`registry::Error::InternalError`] on a duplicate
/// `(capability, extension)` insert.
/// Declares which capabilities an extension provides.
///
/// The left-hand side names the extension type(s) -- one or two,
/// depending on form -- and the right-hand side is a single capability
/// list shared by both execution models.
/// Three forms:
///
/// ```rust,ignore
/// // Shared-only (local consumers served via SharedAsLocal fallback).
/// extension_capabilities!(shared: MyExt => [BearerTokenProvider, KeyValueStore]);
///
/// // Local-only.
/// extension_capabilities!(local: MyLocalExt => [KeyValueStore]);
///
/// // Dual-type -- distinct shared/local types, same capability list.
/// extension_capabilities!(
/// (shared: MySharedKv, local: MyLocalKv) => [KeyValueStore]
/// );
/// ```
///
/// Each capability `$cap` in the list must have a `#[capability]`-generated
/// `shared_entry::<E>` and/or `local_entry::<E>` associated fn. The macro
/// invokes them per listed capability, passing a clone of the extension's
/// instance factory, and inserts the result into the registry.
///
/// In the dual form, `S` must implement `shared::$cap` and `L` must
/// implement `local::$cap` for every capability in the list -- mismatches
/// surface as standard trait-bound errors at the macro call site.
,
register_local: ,
}
};
}