[]Attribute Macro glib::gflags


Attribute macro for defining flags using the bitflags crate. This macro will also define a GFlags::get_type function and the glib::Value traits.

The expected GType name has to be passed as macro attribute. The name and nick of each flag can also be optionally defined. Default name is the flag identifier in CamelCase and default nick is the identifier in kebab-case. Combined flags should not be registered with the GType system and so needs to be tagged with the #[gflags(skip)] attribute.


#[macro_use] extern crate glib;
use glib::prelude::*;
use glib::subclass::prelude::*;

enum MyFlags {
    #[gflags(name = "Flag A", nick = "nick-a")]
    A = 0b00000001,
    #[gflags(name = "Flag B")]
    B = 0b00000010,
    AB = Self::A.bits() | Self::B.bits(),
    C = 0b00000100,