Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andrewbaxter/samevariant
Derive an enum of same-variant pairs
https://github.com/andrewbaxter/samevariant
Last synced: about 22 hours ago
JSON representation
Derive an enum of same-variant pairs
- Host: GitHub
- URL: https://github.com/andrewbaxter/samevariant
- Owner: andrewbaxter
- License: isc
- Created: 2023-01-14T13:17:18.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-07-21T19:08:23.000Z (4 months ago)
- Last Synced: 2024-10-28T22:31:10.679Z (19 days ago)
- Language: Rust
- Size: 4.88 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
README
Derives an enum of same-variant pairs of another enum.
# Installation
```sh
cargo add samevariant
```# Use
Define an enum and use this derive macro:
```
#[samevariant(pub ABCSameVariant)]
pub enum ABC {
A,
B,
C(i32),
}
```It generates a new enum that looks like:
```
enum ABCSameVariant<'l> {
Nonmatching(&'l ABC, &'l ABC),
A,
B,
C(&'l i32, &'l i32),
}impl ABCSameVariant {
fn pairs<'l>(a: &'l ABC, b: &'l ABC) -> ABCSameVariant<'l> {
...
}
}
```If the base enum has a variant `Nonmatching` it will be prefixed by the original enum name (like `ABCNonmatching`).
Only simple and tuple variants are supported, struct-like variants will result in an error.