@@ -124,15 +124,17 @@ impl_tools::impl_scope! {
124
124
125
125
Note: ` #[impl_default] ` is matched within an ` impl_scope! ` regardless of imports.
126
126
127
- ### Impl Scope
127
+ ### Impl Self
128
128
129
- ` impl_scope! ` is a function-like macro used to define a type plus its
130
- implementations. It supports ` impl Self ` syntax:
129
+ ` #[impl_self] ` provides ` impl Self ` syntax, avoiding the
130
+ need to repeat generics when writing impls on a local type definition.
131
+ This supercedes ` impl_scope! ` (except regarding ` macro@impl_default ` ).
131
132
132
133
``` rust
133
134
use std :: fmt :: Display ;
134
135
135
- impl_tools :: impl_scope! {
136
+ #[impl_tools:: impl_self]
137
+ mod NamedThing {
136
138
/// I don't know why this exists
137
139
pub struct NamedThing <T : Display , F > {
138
140
name : T ,
@@ -155,8 +157,9 @@ impl_tools::impl_scope! {
155
157
}
156
158
```
157
159
158
- Caveat: ` rustfmt ` won't currently touch the contents. Hopefully that
159
- [ can be fixed] ( https://github.com/rust-lang/rustfmt/pull/5538 ) !
160
+ Note that ` struct NamedThing ` is defined directly within the outer namespace,
161
+ not within the ` mod NamedThing ` . This is a hack required to ensure the contents
162
+ use valid Rust syntax and are thus formattable using ` cargo fmt ` .
160
163
161
164
### Impl Anon
162
165
@@ -190,7 +193,7 @@ Our macros cannot be extended in the same way, but they can be extended via a ne
190
193
1 . Create a copy of the ` impl-tools ` crate to create a new "front-end" (` proc-macro ` crate).
191
194
This crate is contains only a little code over the [ ` impl-tools-lib ` ] crate.
192
195
2 . To extend ` #[autoimpl] ` , write an impl of [ ` ImplTrait ` ] and add it to the attribute's definition.
193
- To extend ` impl_scope! ` , write an impl of [ ` ScopeAttr ` ] and add it to the macro's definition.
196
+ To extend ` #[impl_self] ` , write an impl of [ ` ScopeAttr ` ] and add it to the macro's definition.
194
197
3 . Depend on your new front end crate instead of ` impl-tools ` .
195
198
196
199
For an example of this approach, see [ kas-macros] ( https://github.com/kas-gui/kas/tree/master/crates/kas-macros ) .
@@ -203,10 +206,7 @@ For an example of this approach, see [kas-macros](https://github.com/kas-gui/kas
203
206
Supported Rust Versions
204
207
------------------------------
205
208
206
- The MSRV is 1.61.0.
207
-
208
- When using a sufficiently recent compiler version (presumably 1.65.0), generic associated types
209
- are supported (only applicable to ` #[autoimpl] ` on trait definitions using GATs).
209
+ The MSRV is 1.65.0.
210
210
211
211
212
212
Alternatives
@@ -273,6 +273,10 @@ trait Foo {
273
273
}
274
274
```
275
275
276
+ [ derive-where] ( https://crates.io/crates/derive-where ) is a variant of the
277
+ standard ` #[derive] ` macro supporting custom generic bounds.
278
+ (This offers a subset of the functionality of ` #[autoimpl] ` ).
279
+
276
280
277
281
Copyright and Licence
278
282
---------------------
0 commit comments