bitflags_derive/
lib.rs

1/*!
2Custom derive attributes for types generated by [`bitflags`](https://docs.rs/bitflags).
3
4## Usage
5
6Add `bitflags-derive` to your `Cargo.toml` alongside `bitflags`:
7
8```toml
9[dependencies.bitflags-derive]
10version = "0.0.4"
11
12[dependencies.bitflags]
13version = "2"
14```
15
16Inside the [`bitflags!` macro](https://docs.rs/bitflags/latest/bitflags/macro.bitflags.html), add a `#[derive]` attribute with any traits from `bitflags-derive` that you'd like to support:
17
18```rust
19#[macro_use]
20extern crate bitflags;
21
22#[macro_use]
23extern crate bitflags_derive;
24
25# fn main() -> Result<(), bitflags::parser::ParseError> {
26bitflags! {
27    #[derive(FlagsDisplay, FlagsFromStr)]
28    struct MyFlags: u8 {
29        const A = 1;
30        const B = 1 << 1;
31        const C = 1 << 2;
32    }
33}
34
35let flags = "A | B".parse::<MyFlags>()?;
36
37assert_eq!("A | B", flags.to_string());
38# Ok(())
39# }
40```
41
42These derives work for any type that implements the [`Flags`](https://docs.rs/bitflags/latest/bitflags/trait.Flags.html) trait.
43*/
44
45#![no_std]
46#![deny(missing_docs)]
47
48#[doc(inline)]
49pub use bitflags_derive_macros::*;
50
51#[doc(hidden)]
52pub mod __private {
53    #[cfg(feature = "serde")]
54    pub mod serde;
55
56    pub use bitflags;
57    pub use core;
58}