Bug 1888590 - Mark some subtests on trusted-types-event-handlers.html as failing...
[gecko.git] / third_party / rust / bitflags / README.md
blobecad515e178889491d01da0ad056f3eacbf60981
1 bitflags
2 ========
4 [![Rust](https://github.com/bitflags/bitflags/workflows/Rust/badge.svg)](https://github.com/bitflags/bitflags/actions)
5 [![Latest version](https://img.shields.io/crates/v/bitflags.svg)](https://crates.io/crates/bitflags)
6 [![Documentation](https://docs.rs/bitflags/badge.svg)](https://docs.rs/bitflags)
7 ![License](https://img.shields.io/crates/l/bitflags.svg)
9 `bitflags` generates flags enums with well-defined semantics and ergonomic end-user APIs.
11 You can use `bitflags` to:
13 - provide more user-friendly bindings to C APIs where flags may or may not be fully known in advance.
14 - generate efficient options types with string parsing and formatting support.
16 You can't use `bitflags` to:
18 - guarantee only bits corresponding to defined flags will ever be set. `bitflags` allows access to the underlying bits type so arbitrary bits may be set.
19 - define bitfields. `bitflags` only generates types where set bits denote the presence of some combination of flags.
21 - [Documentation](https://docs.rs/bitflags)
22 - [Specification](https://github.com/bitflags/bitflags/blob/main/spec.md)
23 - [Release notes](https://github.com/bitflags/bitflags/releases)
25 ## Usage
27 Add this to your `Cargo.toml`:
29 ```toml
30 [dependencies]
31 bitflags = "2.4.1"
32 ```
34 and this to your source code:
36 ```rust
37 use bitflags::bitflags;
38 ```
40 ## Example
42 Generate a flags structure:
44 ```rust
45 use bitflags::bitflags;
47 // The `bitflags!` macro generates `struct`s that manage a set of flags.
48 bitflags! {
49     /// Represents a set of flags.
50     #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
51     struct Flags: u32 {
52         /// The value `A`, at bit position `0`.
53         const A = 0b00000001;
54         /// The value `B`, at bit position `1`.
55         const B = 0b00000010;
56         /// The value `C`, at bit position `2`.
57         const C = 0b00000100;
59         /// The combination of `A`, `B`, and `C`.
60         const ABC = Self::A.bits() | Self::B.bits() | Self::C.bits();
61     }
64 fn main() {
65     let e1 = Flags::A | Flags::C;
66     let e2 = Flags::B | Flags::C;
67     assert_eq!((e1 | e2), Flags::ABC);   // union
68     assert_eq!((e1 & e2), Flags::C);     // intersection
69     assert_eq!((e1 - e2), Flags::A);     // set difference
70     assert_eq!(!e2, Flags::A);           // set complement
72 ```
74 ## Rust Version Support
76 The minimum supported Rust version is documented in the `Cargo.toml` file.
77 This may be bumped in minor releases as necessary.