https://github.com/kijewski/desugar-impl
A macro to allow the use of "field_name: impl SomeTrait" in struct declarations.
https://github.com/kijewski/desugar-impl
Last synced: about 1 year ago
JSON representation
A macro to allow the use of "field_name: impl SomeTrait" in struct declarations.
- Host: GitHub
- URL: https://github.com/kijewski/desugar-impl
- Owner: Kijewski
- License: other
- Created: 2021-07-29T06:19:05.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-08-08T00:33:05.000Z (almost 5 years ago)
- Last Synced: 2025-03-25T05:11:29.980Z (about 1 year ago)
- Language: Rust
- Size: 9.77 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## `impl Trait` not allowed outside of function and method return types
**… but it is now!**
This library gives you one macro, and one macro only: `#[desugar_impl]`.
Annotate any struct, enum, or union with `#[desugar_impl]`
to allow the use of `field_name: impl SomeTrait` in their declaration. E.g.
```
#[desugar_impl]
struct Test {
a: impl Clone + PartialOrd,
b: impl Clone + PartialOrd,
c: impl Hash,
}
```
desugars to
```
struct Test
where
Ty1: Clone + PartialOrd,
Ty2: Clone + PartialOrd,
Ty3: Hash,
{
a: Ty1,
b: Ty2,
c: Ty3,
}
```
You can still place any `#[derive(…)]` macros just below `#[desugar_impl]`, and they'll see
the desugared code.