Trait BooleanFeature

Source
pub trait BooleanFeature<'a>: Sized {
    // Provided method
    fn parse_boolean_feature(
        p: &mut Parser<'a>,
        name: &'static str,
    ) -> Result<(LeftParen, Ident, Option<(Colon, Any)>, RightParen)> { ... }
}
Expand description

This trait provides an implementation for parsing a “Media Feature” in the “Boolean” context. This is complementary to the other media features: RangedFeature and DiscreteFeature.

Rather than implementing this trait on an enum, use the boolean_feature! macro which expands to define the enum and necessary traits (Parse, this trait, and ToCursors) in a single macro call.

It does not implement Parse, but provides parse_boolean_feature(&mut Parser<'a>, name: &str) -> Result<Self>, which can make for a trivial Parse implementation. The name: &str parameter refers to the <feature-name> token, which will be parsed as an Ident.

CSS defines the Media Feature generally as:

 │├─ "(" ─╮─ <feature-name> ─ ":" ─ <value> ─╭─ ")" ─┤│
          ├─ <feature-name> ─────────────────┤
          ╰─ <ranged-feature> ───────────────╯

The RangedFeature trait provides algorithms for parsing <ranged-feature> productions, but boolean features use the other two productions, with some rules around the <value>.

A boolean media query:

  • Can omit the the : and <value>.
  • Must allow any token as the <value>, but the <dimension> of 0, <number> of 0 and <ident> of none will mean the query evaluates to false.

Given these, this trait parses as:

<boolean-feature>
 │├─ "(" ─╮─ <feature-name> ─ ":" ─ <any> ─╭─ ")" ─┤│
          ╰─ <feature-name> ───────────────╯

Provided Methods§

Source

fn parse_boolean_feature( p: &mut Parser<'a>, name: &'static str, ) -> Result<(LeftParen, Ident, Option<(Colon, Any)>, RightParen)>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§