Crate option_set

source ·
Expand description

A macro and a trait for implementing a bitset/flag type that serializes to and deserializes from a sequence of strings.

Usage

option_set::option_set! {
    struct FooOptions: UpperCamel + u16 {
        const BAR_FIRST        = 0x0001;
        const QUX_SECOND_THING = 0x0080;
        const LOL_3RD          = 0x4000;
    }
}

let opts_in = FooOptions::BAR_FIRST | FooOptions::LOL_3RD;
let json = serde_json::to_string_pretty(&opts_in).unwrap();

println!("{}", json);

let opts_out: FooOptions = serde_json::from_str(&json).unwrap();

println!("{:?}", opts_out);
assert!(opts_out == opts_in);

Macros

Enums

  • Type that knows how to transform the case of individual option flag names.

Traits

  • Trait for bit flags that forwards to std traits for useful bit operators.

Functions

  • Deserialize set bits from a sequence of name strings.
  • Serialize an OptionSet’s set bits as a sequence of strings.