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
use TokenStream;
/// Annotate an enum with this to implement a specified trait
///
/// When `implement(SomeTrait)` is used on `SomeEnum`, it generates the following implementations:
/// - `SomeTrait for SomeEnum`
/// - For each `SomeEnum` variant `VariantName(VariantType)`:
/// - `From<VariantType> for SomeEnum`
/// - `TryInto<VariantType> for SomeEnum`
/// - `TryInto<&VariantType> for &SomeEnum`
/// - `TryInto<&mut VariantType> for &mut SomeEnum`
///
/// All enum fields must be of the form `VariantName(VariantType)`
///
/// # Registered Traits
///
/// If you can annotate the trait you wish to implement with [macro@register], the API is really simple. Simply pass the trait as the only argument to this attribute.
///
/// Syntax: `implement(trait name)`
///
/// Example:
/// ```
/// #[enum_delegate::register]
/// trait Foo {}
///
/// struct Bar;
/// impl Foo for Bar {}
///
/// #[enum_delegate::implement(Foo)]
/// enum FooEnum {
/// Bar(Bar),
/// }
/// ```
///
/// # Unregistered Traits
///
/// In some cases, you may not be able to [macro@register] a trait (for example, if it lives in a 3rd-party crate). You can still use this attribute, but you'll have to pass in the trait definition as the second argument.
///
/// Syntax: `implement(trait name, trait definition)`
///
/// Example:
/// ```
/// trait Foo {}
///
/// struct Bar;
/// impl Foo for Bar {}
///
/// #[enum_delegate::implement{
/// Foo,
/// trait Foo {}
/// }]
/// enum FooEnum {
/// Bar(Bar),
/// }
/// ```
///
/// See the [crate-level documentation](crate) for more information.
/// Annotate a trait with this so that it can be more easily used with [macro@implement]
///
/// Example:
///
/// ```
/// #[enum_delegate::register]
/// trait Foo {}
///
/// struct Bar;
/// impl Foo for Bar {}
///
/// #[enum_delegate::implement(Foo)]
/// enum FooEnum {
/// Bar(Bar),
/// }
/// ```
///
/// Note: this macro generates a macro with the same name as the trait it is used on. This may cause a conflict if used together with another macro library that also generates such a macro. A workaround is to not register the trait (see [macro@implement] documentation for how you can still implement it)
///
/// See the [crate-level documentation](crate) for more information.
/// Annotate a trait with this to implement it for a specified enum
///
/// When `implement_for(SomeEnum)` is used on `SomeTrait`, it implements `SomeTrait for SomeEnum`. Unlike [macro@implement], it does not generate conversion implementations for `SomeEnum`.
///
/// All enum fields must be of the form `VariantName(VariantType)`
///
/// Syntax: `implement_for(enum name, enum definition)`
///
/// Example:
///
/// ```
/// #[enum_delegate::implement_for{
/// FooEnum,
/// enum FooEnum {
/// Bar(Bar),
/// }
/// }]
/// trait Foo {}
///
/// struct Bar;
/// impl Foo for Bar {}
///
/// enum FooEnum {
/// Bar(Bar),
/// }
/// ```
///
/// See the [crate-level documentation](crate) for more information.
/// Annotate an enum with this to implement [`From`] and [`TryInto`] conversions for it.
///
/// When `implement_conversions` is used on `SomeEnum`, it generates the following implementations:
/// - For each `SomeEnum` variant `VariantName(VariantType)`:
/// - `From<VariantType> for SomeEnum`
/// - `TryInto<VariantType> for SomeEnum`
/// - `TryInto<&VariantType> for &SomeEnum`
/// - `TryInto<&mut VariantType> for &mut SomeEnum`
///
/// All enum fields must be of the form `VariantName(VariantType)`
/// Not part of the public API; used by `[register]`-generated code