Crate option_set [−] [src]
A macro and a trait for implementing a bitset/flag type that serializes to and deserializes from a sequence of strings.
Usage
#[macro_use] extern crate option_set; #[macro_use] extern crate bitflags; extern crate serde; extern crate serde_json; option_set! { struct FooOptions: UpperCamel + u16 { const BAR_FIRST = 0x0001; const QUX_SECOND_THING = 0x0080; const LOL_3RD = 0x4000; } } fn main() { 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
option_set |
Defines an option set type. |
Enums
CaseTransform |
A Type that knows how to transform the case of individual option flag names. |
Traits
OptionSet |
Trait for bit flags that forwards to std traits for useful bit operators. |
Functions
deserialize |
Deserialize set bits from a sequence of name strings. |
serialize |
Serialize an OptionSet's set bits as a sequence of strings. |