Skip to content

Update README and top-level doc #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,17 @@ impl_tools::impl_scope! {

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

### Impl Scope
### Impl Self

`impl_scope!` is a function-like macro used to define a type plus its
implementations. It supports `impl Self` syntax:
`#[impl_self]` provides `impl Self` syntax, avoiding the
need to repeat generics when writing impls on a local type definition.
This supercedes `impl_scope!` (except regarding `macro@impl_default`).

```rust
use std::fmt::Display;

impl_tools::impl_scope! {
#[impl_tools::impl_self]
mod NamedThing {
/// I don't know why this exists
pub struct NamedThing<T: Display, F> {
name: T,
Expand All @@ -155,8 +157,9 @@ impl_tools::impl_scope! {
}
```

Caveat: `rustfmt` won't currently touch the contents. Hopefully that
[can be fixed](https://github.com/rust-lang/rustfmt/pull/5538)!
Note that `struct NamedThing` is defined directly within the outer namespace,
not within the `mod NamedThing`. This is a hack required to ensure the contents
use valid Rust syntax and are thus formattable using `cargo fmt`.

### Impl Anon

Expand Down Expand Up @@ -190,7 +193,7 @@ Our macros cannot be extended in the same way, but they can be extended via a ne
1. Create a copy of the `impl-tools` crate to create a new "front-end" (`proc-macro` crate).
This crate is contains only a little code over the [`impl-tools-lib`] crate.
2. To extend `#[autoimpl]`, write an impl of [`ImplTrait`] and add it to the attribute's definition.
To extend `impl_scope!`, write an impl of [`ScopeAttr`] and add it to the macro's definition.
To extend `#[impl_self]`, write an impl of [`ScopeAttr`] and add it to the macro's definition.
3. Depend on your new front end crate instead of `impl-tools`.

For an example of this approach, see [kas-macros](https://github.com/kas-gui/kas/tree/master/crates/kas-macros).
Expand All @@ -203,10 +206,7 @@ For an example of this approach, see [kas-macros](https://github.com/kas-gui/kas
Supported Rust Versions
------------------------------

The MSRV is 1.61.0.

When using a sufficiently recent compiler version (presumably 1.65.0), generic associated types
are supported (only applicable to `#[autoimpl]` on trait definitions using GATs).
The MSRV is 1.65.0.


Alternatives
Expand Down Expand Up @@ -273,6 +273,10 @@ trait Foo {
}
```

[derive-where](https://crates.io/crates/derive-where) is a variant of the
standard `#[derive]` macro supporting custom generic bounds.
(This offers a subset of the functionality of `#[autoimpl]`).


Copyright and Licence
---------------------
Expand Down
15 changes: 6 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,18 @@
//! [`#[autoimpl]`](macro@autoimpl) is an alternative to
//! [`#[derive]`](macro@derive) with more features (also usable on traits).
//!
//! [`#[impl_default]`](macro@impl_default) is shorthand for implementing
//! [`Default`] with an explicit default value.
//! It supports structs and enums.
//! [`#[impl_default]`](macro@impl_default) is an alternative to
//! `#[derive(Default)]` supporting field initializers.
//!
//! [`impl_scope!`] is a function-like macro used to define a type together with
//! its implementations. This allows:
//!
//! - `impl Self` syntax (avoid repeated definitions of generics)
//! - Evaluation of some more complex attribute macros
//! [`#[impl_self]`](macro@impl_self) provides `impl Self` syntax, avoiding the
//! need to repeat generics when writing impls on a local type definition.
//! This supercedes [`impl_scope!`] (except regarding [`macro@impl_default`]).
//!
//! [`impl_anon!`] is a function-like macro used to define and instantiate a
//! unique (single-use) type. It supports everything supported by [`impl_scope!`]
//! plus field initializers and (limited) automatic typing of fields.
//!
//! User-extensions to both [`#[autoimpl]`](macro@autoimpl) and [`impl_scope!`]
//! User-extensions to both [`#[autoimpl]`](macro@autoimpl) and [`macro@impl_self`]
//! are possible with a custom proc-macro crate depending on
//! [impl-tools-lib](https://crates.io/crates/impl-tools-lib).
Expand Down