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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
// The library uses no unsafe; missing docs are rejected as errors (only for pub items;
// internal pub(crate) is exempt).
// The MSVC linker prints "creating library ... and object ..." to stdout, which rustc
// treats as linker_messages warnings; these are harmless Windows link-product notices,
// suppressed globally.
// The `delimiter!` macro is defined at the top of preprocess and imported into the crate
// root via `#[macro_use]`; textual scope requires its declaration to precede all users
// (fuzz / parse / this module).
pub
use ;
use ;
pub use TraitBounds;
pub use ;
use ;
use compile_error_str;
/// Attribute macro that generates `impl` blocks for a trait in batch.
///
/// Annotate a trait definition with `#[batch_impl(...)]`; every impl-spec in the macro
/// arguments generates a corresponding `impl` block for that trait.
///
/// ## Syntax
///
/// ```text
/// #[batch_impl( impl-spec [, impl-spec]* [{ body }]? )]
/// ```
///
/// An impl-spec has three parts (the tail of each part may be omitted):
/// - `<impl generics>` — generic params of the `impl` block
/// - `Trait name<trait generics>` — the trait's generic args and associated type bindings
/// - target type — wrapped in `[]` for a parallel list, `^`/`-` for generic application
///
/// ## Examples
///
/// ```
/// # use batch_impl::batch_impl;
/// #[batch_impl(usize, isize)]
/// trait Numeric {}
///
/// #[batch_impl(<T> Vec<T>)]
/// trait Collection {}
///
/// #[batch_impl(<T> FromValue<T> [i32 { fn wrap(_: T) -> Self { 0 }}, u32 #wrap{0}] )]
/// trait FromValue<T> { fn wrap(val: T) -> Self; }
///
/// // #name{body} also supports const and type items
/// #[batch_impl(usize #MY_CONST{42})]
/// trait HasConst { const MY_CONST: usize; }
///
/// ```
/// Same as `#[batch_impl]`, but discards the annotated trait definition and only emits
/// `impl` blocks.
///
/// For traits already defined elsewhere where only batched impl generation is needed. The
/// annotated trait merely serves as the "signature source of truth" for the directive system:
/// `#name`/`#fill`/`#delegate` read item signatures from it, and the open extension
/// `#name(args){body}` hands (method name list, body, the whole trait) to the user's
/// same-named function-like macro (see README "Directive System"). The syntax is identical
/// to `#[batch_impl]`.
///
/// ## Examples
///
/// ```
/// # use batch_impl::batch_impl_only;
/// trait Greet { fn hello(&self) -> &str; }
///
/// #[batch_impl_only(usize #hello{"hi"})]
/// trait Greet { fn hello(&self) -> &str; } // this trait definition is dropped, existing definitions are unaffected
/// // Written with batch_impl_only instead of batch_trait to use the directive system; write it verbatim at the trait definition site
/// ```
/// Function-like macro that generates `impl` blocks for a declared trait in batch.
///
/// Syntax: `unsafe? Trait path: impl-specs;`, with `;` separating multiple trait segments.
/// After each segment's `:` comes a DSL expression (type DSL + `@` constants, same as
/// `#[batch_impl]`).
///
/// **`#` directives are not supported** (`#fill`/`#delegate`/`#blanket`/open extension):
/// directives need the trait definition as the signature source of truth, which `batch_trait!`
/// as a function-like macro cannot access; use `#[batch_impl]` / `#[batch_impl_only]` when
/// you need directives.
///
/// ## Examples
///
/// ```
/// # use batch_impl::batch_trait;
/// trait A {}
/// trait B<T> {}
/// unsafe trait UnsafeTrait{}
///
/// batch_trait!(
/// A: usize, isize;
/// B: <T> B<T> Vec<T>;
/// unsafe UnsafeTrait: usize
/// );
/// ```
///
/// Path traits (such as `foo::C`) are supported too; see tests/regression.rs.
/// Test-only open-extension macro (function-like): `name!{(method name list){body} trait T {...}}`.
///
/// Parses the method name list, body, and trait definition from the macro input, generating
/// `fn signature { body }` per method (reusing the trait signature) — equivalent to handing
/// the `#fill` implementation to the user.
///
/// Used to verify open instruction extension: `#name(args){body}` expands to
/// `{name!{(args){body} trait ...}}`, with the macro call landing in the impl body and being
/// expanded by the user macro into the needed fn definitions based on the trait
/// (see section 28 of `tests/dsl.rs`).
///
/// Design point: this must be a **function-like macro call** `name!{...}`, not an
/// `#[name[...]] trait ...` attribute — a trait is not a valid item inside an impl block
/// (`#[attr] trait` cannot appear in an impl), whereas a function-like macro in an impl
/// body position is expanded by rustc into associated items.
// ============================================================
// Documentation placeholders for the DSL directive / macro-meta layers.
//
// The `#` directives and `@` constants live inside macro arguments, so IDE
// hover and docs.rs cannot reach them. Each placeholder below is a public
// no-op function whose doc block documents one directive — a hoverable,
// searchable rustdoc entry. Never call these functions.
// ============================================================
/// Documentation placeholder for the `#delegate` directive.
///
/// `#delegate(args){target}` generates one delegation call per selected
/// method: each becomes `fn m(&self, ...) -> R { (target).m(...) }`. The
/// `self` argument is skipped; the remaining arguments are forwarded (named
/// params as-is, non-identifier patterns renamed to `arg{i}` when they
/// cannot be used as an expression).
///
/// ```
/// # use batch_impl::batch_impl;
/// #[batch_impl(
/// Vec<u32> #d_len{self.len()},
/// Box<Vec<u32>> #delegate(d_len){**self}
/// )]
/// trait MyLen { fn d_len(&self) -> usize; }
/// # fn main() {}
/// ```
///
/// **Documentation marker only — never call this function.**
/// Documentation placeholder for the `#fill` directive.
///
/// `#fill(args){body}` copies each selected trait item's signature and
/// substitutes `body` as its implementation. Selection supports the `@all`
/// families (`@all_methods`, `@all_ref_methods`, `@all_default_methods`,
/// ...), individual names, and `-` subtraction (`#fill(@all_methods, -foo)`).
///
/// ```
/// # use batch_impl::batch_impl;
/// #[batch_impl(Vec<u32> #fill(@all_methods){0})]
/// trait F { fn zero(&self) -> u32; }
/// # fn main() {}
/// ```
///
/// **Documentation marker only — never call this function.**
/// Documentation placeholder for the `#blanket` directive.
///
/// `#blanket(args){wrapper list}` implements the trait for every wrapper
/// around a fresh generic `T`, delegating each method by deref. Wrappers may
/// carry a `:N` deref-depth annotation and a `where{...}` predicate; a
/// wrapper whose main part contains `@0` treats `@0` as T's position
/// (`(u32, @0)` → `(u32, T)`), otherwise it is applied as `wrapper^T`.
///
/// ```
/// # use batch_impl::batch_impl;
/// #[batch_impl(#blanket(@all_methods){Box})]
/// trait B { fn tag(&self) -> u32; }
/// # fn main() {}
/// ```
///
/// **Documentation marker only — never call this function.**
/// Documentation placeholder for the `#name{body}` fill-by-name directive.
///
/// `#name{body}` looks up the single trait item named `name` — a method, an
/// associated const, or an associated type — and fills it with `body` (the
/// body must match that item's shape).
///
/// ```
/// # use batch_impl::batch_impl;
/// #[batch_impl(Box<Vec<u32>> #count{self.len()})]
/// trait L { fn count(&self) -> usize; }
/// # fn main() {}
/// ```
///
/// **Documentation marker only — never call this function.**
/// Documentation placeholder for the open-extension protocol.
///
/// A `#name(args){body}` whose `name` is not a built-in directive expands to
/// a call of a user-defined function-like macro of the same name, handed the
/// args, body and trait definition:
/// `#my_ext(x){y}` → `{ my_ext!{ (x) {y} trait_def } }`.
///
/// ```
/// # use batch_impl::batch_impl;
/// macro_rules! my_ext { ($($rest:tt)*) => {}; }
/// #[batch_impl(Box<u32> #my_ext(x){y})]
/// trait O {}
/// # fn main() {}
/// ```
///
/// **Documentation marker only — never call this function.**
/// Documentation placeholder for the `@` macro-meta constant system.
///
/// `@` names expand before all other DSL processing (`@ <> # where` order):
/// - built-in name families: `@uint` / `@int` / `@float` / `@num` /
/// `@scalar` and wildcards `@u*` / `@i*` / `@f*`;
/// - range families: `@u8..u128` / `@i8..i128` / `@f32..f64` (inclusive);
/// - `batch_trait!` user constants: a leading `@name = value;` segment
/// (lazy expansion, reference checks);
/// - `@N` position references (resolved by codegen) and `@trait`
/// (segment-level trait path).
///
/// ```
/// # use batch_impl::batch_impl;
/// #[batch_impl(Box^@u*)]
/// trait C {}
/// # fn main() {}
/// ```
///
/// **Documentation marker only — never call this function.**