Skip to content

Commit 416fa25

Browse files
authored
Merge pull request #54 from kas-gui/push-tpwmyomltrry
Update README and top-level doc
2 parents 2d60bcb + 8a501af commit 416fa25

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,17 @@ impl_tools::impl_scope! {
124124

125125
Note: `#[impl_default]` is matched within an `impl_scope!` regardless of imports.
126126

127-
### Impl Scope
127+
### Impl Self
128128

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`).
131132

132133
```rust
133134
use std::fmt::Display;
134135

135-
impl_tools::impl_scope! {
136+
#[impl_tools::impl_self]
137+
mod NamedThing {
136138
/// I don't know why this exists
137139
pub struct NamedThing<T: Display, F> {
138140
name: T,
@@ -155,8 +157,9 @@ impl_tools::impl_scope! {
155157
}
156158
```
157159

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`.
160163

161164
### Impl Anon
162165

@@ -190,7 +193,7 @@ Our macros cannot be extended in the same way, but they can be extended via a ne
190193
1. Create a copy of the `impl-tools` crate to create a new "front-end" (`proc-macro` crate).
191194
This crate is contains only a little code over the [`impl-tools-lib`] crate.
192195
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.
194197
3. Depend on your new front end crate instead of `impl-tools`.
195198

196199
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
203206
Supported Rust Versions
204207
------------------------------
205208

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.
210210

211211

212212
Alternatives
@@ -273,6 +273,10 @@ trait Foo {
273273
}
274274
```
275275

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+
276280

277281
Copyright and Licence
278282
---------------------

src/lib.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,18 @@
1212
//! [`#[autoimpl]`](macro@autoimpl) is an alternative to
1313
//! [`#[derive]`](macro@derive) with more features (also usable on traits).
1414
//!
15-
//! [`#[impl_default]`](macro@impl_default) is shorthand for implementing
16-
//! [`Default`] with an explicit default value.
17-
//! It supports structs and enums.
15+
//! [`#[impl_default]`](macro@impl_default) is an alternative to
16+
//! `#[derive(Default)]` supporting field initializers.
1817
//!
19-
//! [`impl_scope!`] is a function-like macro used to define a type together with
20-
//! its implementations. This allows:
21-
//!
22-
//! - `impl Self` syntax (avoid repeated definitions of generics)
23-
//! - Evaluation of some more complex attribute macros
18+
//! [`#[impl_self]`](macro@impl_self) provides `impl Self` syntax, avoiding the
19+
//! need to repeat generics when writing impls on a local type definition.
20+
//! This supercedes [`impl_scope!`] (except regarding [`macro@impl_default`]).
2421
//!
2522
//! [`impl_anon!`] is a function-like macro used to define and instantiate a
2623
//! unique (single-use) type. It supports everything supported by [`impl_scope!`]
2724
//! plus field initializers and (limited) automatic typing of fields.
2825
//!
29-
//! User-extensions to both [`#[autoimpl]`](macro@autoimpl) and [`impl_scope!`]
26+
//! User-extensions to both [`#[autoimpl]`](macro@autoimpl) and [`macro@impl_self`]
3027
//! are possible with a custom proc-macro crate depending on
3128
//! [impl-tools-lib](https://crates.io/crates/impl-tools-lib).
3229

0 commit comments

Comments
 (0)