Macro boolean_feature

Source
macro_rules! boolean_feature {
    ($(#[$meta:meta])* $vis:vis enum $feature: ident<$feature_name: tt>) => { ... };
}
Expand description

This macro expands to define an enum which already implements Parse and BooleanFeature, for a one-liner definition of a BooleanFeature.

ยงExample

use css_parse::*;
use bumpalo::Bump;

// Define the Boolean Feature.
boolean_feature! {
    /// A boolean media feature: `(test-feature)`
    pub enum TestFeature<"test-feature">
}

// Test!
let allocator = Bump::new();
let mut p = Parser::new(&allocator, "(test-feature)");
let result = p.parse_entirely::<TestFeature>();
assert!(matches!(result.output, Some(TestFeature::Bare(open, ident, close))));

let mut p = Parser::new(&allocator, "(test-feature: none)");
let result = p.parse_entirely::<TestFeature>();
assert!(matches!(result.output, Some(TestFeature::WithValue(open, ident, colon, any, close))));