https://github.com/property404/bool-like
Proc macro for implementing `Not` on two-variant enums
https://github.com/property404/bool-like
Last synced: about 1 year ago
JSON representation
Proc macro for implementing `Not` on two-variant enums
- Host: GitHub
- URL: https://github.com/property404/bool-like
- Owner: Property404
- Created: 2023-03-11T00:32:51.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-01T19:40:54.000Z (almost 3 years ago)
- Last Synced: 2025-02-02T11:41:37.946Z (over 1 year ago)
- Language: Rust
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Bool-Like
This crate contains an attribute macro `#[bool_like]`. By default, this macro
just implements `std::ops::Not` for a simple two-variant enum. `!` applied to
one variant will produce the other.
Optionally, the sub-attribute `#[into_false]` may be applied to one of the
variants to indicate that variant is equivalent to `false`, and the other
variant is equivalent to `true`. `std::convert::From` will be implemented for
both the enum and `bool`.
```rust
use bool_like::bool_like;
/// An answer to a question.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[bool_like]
enum Answer {
#[into_false]
No,
Yes,
}
assert_eq!(! Answer::No, Answer::Yes);
assert!(bool::from(Answer::Yes));
```
## License
MIT or Apache 2.0