flags-macro

Crates.ioflags-macro
lib.rsflags-macro
version0.1.4
sourcesrc
created_at2018-11-24 06:59:46.688566
updated_at2020-01-08 14:13:44.127114
descriptionProvides a helper macro for writing bitflags.
homepage
repositoryhttps://github.com/yvt/flags-macro-rs
max_upload_size
id98384
size15,587
yvt (yvt)

documentation

README

flags-macro

docs.rs

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.

Examples

bitflags:

#[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:

#[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

Commit count: 12

cargo fmt