#bit-flags #enums #flags #bit #bitmask

无 std encap_enum

一种定义一组常量和位标志的非冗余方式

2 个版本

0.3.1 2020 年 7 月 13 日
0.3.0 2020 年 7 月 13 日
0.2.1 2020 年 7 月 11 日
0.1.5 2020 年 6 月 19 日

170无标准库

每月 27 次下载

MIT 许可证

32KB
572

Encap_Enum

Rust

Encap_Enum 为定义枚举、位标志和常量组提供 encap_enum! 宏。

用法

将此添加到您的 Cargo.toml

[dependencies]
encap_enum = "0.3.1"

并将此添加到您的 crate 根目录

#[macro_use]
extern crate encap_enum;

功能

  • 迭代器。
  • 位标志。
  • 封装的标志值。
    • 更改 enum 的可见性,包括内部值和枚举本身。
  • 支持任意数量的属性。
    • 这包括文档注释,#[repr(C)]#[derive] 和许多其他属性。
  • 无 std 依赖。
  • FFI 兼容。

示例

encap_enum!{
    /// ClassStyle is a structure used in the Window class.
    #[repr(C)]
    pub enum ClassStyle: pub u32 {
        ByteAlignClient     = 0x0000_1000,
        ByteAlignWindow     = 0x0000_2000, /// Aligns window on a byte boundary.
        DoubleClicks        = 0x0000_0008,
        DropShadow          = 0x0002_0000,
        GlobalClass         = 0x0000_4000,
        // ...
    }
}
fn main() {
    println!("ByteAlignClient integer representation: {}", ClassStyle::ByteAlignClient.raw);
    println!("ByteAlignClient debug representation: {:?}", ClassStyle::ByteAlignClient);
}

许可证

encap_enumMIT 许可证 下授权。

最近更改
  • 修复了错误的文档。

无运行时依赖