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
/// Procedural macro for generating `impl` blocks with inherent methods and trait implementations.
///
/// The `blockset!` macro allows defining inherent methods and trait implementations for a type
/// in a single, cohesive syntax block.
///
/// # Syntax
///
/// ```text
/// impl<ImplGenerics> Type<TypeGenerics>
/// where
/// ...;
///
/// fn method1(...) { ... }
/// fn method2(...) -> T { ... }
///
/// path::ToTrait<TraitGenerics> {
/// fn trait_method(...) -> ... { ... }
/// }
/// ```
///
/// - The `impl` line defines the target type, optionally with generics and a `where` clause.
/// - Any `fn` blocks after the header are treated as inherent methods.
/// - Any block with a `trait_path { ... }` format is interpreted as a trait implementation block.
///
/// # Example
///
/// ```rust
/// use toga::impls;
///
/// trait Health<T> {
/// fn health(&self) -> T;
/// }
///
/// trait Wizard {
/// fn you_shall_not_pass(&self) {}
/// }
///
/// struct Player<const A: usize, B>(B);
///
/// impls! {
/// impl<const A: usize, B> Player<A, B>
/// where
/// B: Clone;
///
/// pub fn hello_world(&self) {}
///
/// pub fn give_me_a_number(&self) -> u8 {
/// 50
/// }
///
/// Wizard {}
///
/// Health<u8> {
/// fn health(&self) -> u8 {
/// 100
/// }
/// }
/// }
/// ```
///
/// # Notes
///
/// - All generics and where clauses are applied to both the inherent and trait impls.
/// - The trait paths must be valid and resolvable in scope (e.g., `self::TraitName` or `crate::TraitName`).
/// - Multiple trait blocks and methods are supported.