https://github.com/yvt/flags-macro-rs
Provides a helper macro for writing bitflags in Rust.
https://github.com/yvt/flags-macro-rs
Last synced: 4 months ago
JSON representation
Provides a helper macro for writing bitflags in Rust.
- Host: GitHub
- URL: https://github.com/yvt/flags-macro-rs
- Owner: yvt
- License: cc0-1.0
- Created: 2018-11-24T06:42:26.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-01-08T14:13:04.000Z (over 6 years ago)
- Last Synced: 2025-06-22T02:50:08.004Z (about 1 year ago)
- Language: Rust
- Size: 7.81 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# flags-macro
[
](https://docs.rs/flags-macro/)
This crate provides a convenient macro `flags` for constructing bitflags.
It's designed to be compatible with [`bitflags`] and [`enumflags`] but works
with any bitflags-like types.
[`bitflags`]: https://crates.io/crates/bitflags
[`enumflags`]: https://crates.io/crates/enumflags
## Examples
`bitflags`:
```rust
#[macro_use]
extern crate bitflags;
bitflags! {
struct Test: u32 {
const A = 0b0001;
const B = 0b0010;
}
}
let flags0 = flags![Test::{}];
let flags1 = flags![Test::{A}];
let flags2 = flags![Test::{A | B}];
assert_eq!(flags0, Test::empty());
assert_eq!(flags1, Test::A);
assert_eq!(flags2, Test::A | Test::B);
```
`enumflags`:
```rust
#[macro_use]
extern crate enumflags;
#[derive(EnumFlags, Copy, Clone, PartialEq, Eq, Debug)]
#[repr(u8)]
pub enum Test { A = 0b0001, B = 0b0010 }
let flags0 = flags![Test::{}];
let flags1 = flags![Test::{A}];
let flags2 = flags![Test::{A | B}];
assert_eq!(flags0, enumflags::BitFlags::empty());
assert_eq!(flags1, Test::A);
assert_eq!(flags2, Test::A | Test::B);
```
License: CC0-1.0