Macro features::features
[−]
[src]
macro_rules! features { (mod $mod_name:ident { $($(#[$flag_attr:meta])* const $flag:ident = $value:expr),+ }) => { ... }; (pub mod $mod_name:ident { $($(#[$flag_attr:meta])* const $flag:ident = $value:expr),+ }) => { ... }; (@_impl mod $mod_name:ident { $($(#[$flag_attr:meta])* const $flag:ident = $value:expr),+ }) => { ... }; }
The features!
macro generates a module to contain all feature toggling logic.
Examples
Basic example:
#[macro_use] extern crate bitflags; #[macro_use] extern crate features; features! { pub mod feature { const Alpha = 0b00000001, const Beta = 0b00000010 } } fn main() { assert_eq!(false, feature::is_enabled(feature::Alpha)); assert_eq!(false, feature::is_enabled(feature::Beta)); feature::enable(feature::Beta); assert_eq!(false, feature::is_enabled(feature::Alpha)); assert_eq!(true, feature::is_enabled(feature::Beta)); }
Multiple feature sets:
#[macro_use] extern crate bitflags; #[macro_use] extern crate features; features! { pub mod ux { const JsonOutput = 0b10000000, const VerboseOutput = 0b01000000 } } features! { pub mod srv { const Http2Downloading = 0b10000000, const BitTorrentDownloading = 0b01000000 } } fn main() { // Parse CLI args, environment, read config file etc... srv::enable(srv::BitTorrentDownloading); ux::enable(ux::JsonOutput); if srv::is_enabled(srv::Http2Downloading) { println!("Downloading via http2..."); } else if srv::is_enabled(srv::BitTorrentDownloading) { println!("Downloading via bit torrent..."); } else { println!("Downloading the old fashioned way..."); } if ux::is_enabled(ux::VerboseOutput) { println!("COOL"); } }