pub trait FeatureConditionList<'a>: Sized + Parse<'a>where
Self: 'a,{
type FeatureCondition: Sized + Parse<'a>;
// Required methods
fn build_is(feature: Self::FeatureCondition) -> Self;
fn build_not(
keyword: ConditionKeyword,
features: Self::FeatureCondition,
) -> Self;
fn build_and(
features: Vec<'a, (Self::FeatureCondition, Option<ConditionKeyword>)>,
) -> Self;
fn build_or(
features: Vec<'a, (Self::FeatureCondition, Option<ConditionKeyword>)>,
) -> Self;
// Provided method
fn parse_condition(p: &mut Parser<'a>) -> Result<Self> { ... }
}
Expand description
This trait can be used for AST nodes representing a list of “Feature Conditions”. This is an amalgamation of
Supports Conditions, Media Conditions, and Container Queries
This is an implementation of <at-rule-list>
.
Looking at <supports-condition>
and <container-query>
we can se almost identical grammars (eliding some tokens
for brevity):
<supports-condition>
│├─╮─ <ident-token "not"> ─ <supports-in-parens> ──────────────────────────────╭──┤│
╰─ <supports-in-parens> ─╮─╭─ <ident-token "and"> ─ <supports-in-parens> ─╮─┤
│ ╰──────────────────────────────────────────────╯ │
├─╭─ <ident-token "or"> ─ <supports-in-parens> ─╮──┤
│ ╰─────────────────────────────────────────────╯ │
╰──────────────────────────────────────────────────╯
<container-query>
│├─╮─ <ident-token "not"> ─ <query-in-parens> ───────────────────────────╭──┤│
╰─ <supports-in-parens> ─╮─╭─ <ident-token "and"> ─ <supports-in-parens> ─╮─┤
│ ╰──────────────────────────────────────────────╯ │
├─╭─ <ident-token "or"> ─ <supports-in-parens> ─╮──┤
│ ╰─────────────────────────────────────────────╯ │
╰──────────────────────────────────────────────────╯
<media-condition>
│├─╮─ <ident-token "not"> ─ <media-in-parens> ───────────────────────────╭──┤│
╰─ <media-in-parens> ─╮─╭─ <ident-token "and"> ─ <media-in-parens> ─╮─┤
│ ╰───────────────────────────────────────────╯ │
│─╭─ <ident-token "or"> ─ <media-in-parens> ─╮──│
│ ╰──────────────────────────────────────────╯ │
╰───────────────────────────────────────────────╯
The key difference between each of these is their own <*-in-parens>
tokens. Thus they could all be defined as:
<condition-prelude-list>
│├─╮─ <ident-token "not"> ─ <feature> ───────────────────╭──┤│
╰─ <feature> ─╮─╭─ <ident-token "and"> ─ <feature> ─╮─┤
│ ╰───────────────────────────────────╯ │
│─╭─ <ident-token "or"> ─ <feature> ─╮──│
│ ╰──────────────────────────────────╯ │
╰───────────────────────────────────────╯
Where <feature>
is defined by [FeatureConditionList::FeatureCondition]
, which is required to implement Parse.
There is a further subtle change for this trait, which is the introduction of the ConditionKeyword enum to better
reason about the given condition keyword. This makes the final grammar:
<condition-keyword>
│├──╮─ <ident-token "not"> ─╭──┤│
├─ <ident-token "and"> ─┤
╰─ <ident-token "or"> ──╯
<condition-prelude-list>
│├─╮─ <condition-keyword "not"> ─ <feature> ───────────────────╭──┤│
╰─ <feature> ─╮─╭─ <condition-keyword "and"> ─ <feature> ─╮─┤
│ ╰─────────────────────────────────────────╯ │
│─╭─ <condition-keyword "or"> ─ <feature> ─╮──│
│ ╰────────────────────────────────────────╯ │
╰─────────────────────────────────────────────╯
Required Associated Types§
type FeatureCondition: Sized + Parse<'a>
Required Methods§
fn build_is(feature: Self::FeatureCondition) -> Self
fn build_not( keyword: ConditionKeyword, features: Self::FeatureCondition, ) -> Self
fn build_and( features: Vec<'a, (Self::FeatureCondition, Option<ConditionKeyword>)>, ) -> Self
fn build_or( features: Vec<'a, (Self::FeatureCondition, Option<ConditionKeyword>)>, ) -> Self
Provided Methods§
fn parse_condition(p: &mut Parser<'a>) -> Result<Self>
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.