Macro discrete_feature

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

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

ยงExample

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

keyword_set!(
    /// A keyword that defines text-feature options
    pub enum FeatureKeywords {
        Big: "big",
        Small: "small",
    }
);

// Define the Discrete Feature.
discrete_feature! {
    /// A discrete media feature: `(test-feature: big)`, `(test-feature: small)`
    pub enum TestFeature<"test-feature", FeatureKeywords>
}

// 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: big)");
let result = p.parse_entirely::<TestFeature>();
assert!(matches!(result.output, Some(TestFeature::WithValue(open, ident, colon, any, close))))