pub trait DiscreteFeature<'a>: Sized {
type Value: Parse<'a>;
// Provided method
fn parse_descrete_feature(
p: &mut Parser<'a>,
name: &'static str,
) -> Result<(LeftParen, Ident, Option<(Colon, Self::Value)>, RightParen)> { ... }
}
Expand description
This trait provides an implementation for parsing a “Media Feature” that has a discrete keyword. This is complementary to the other media features: BooleanFeature and DiscreteFeature.
Rather than implementing this trait on an enum, use the discrete_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_discrere_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. The DiscreteFeature::Value type must be implemented, and defines the
<value>
portion. Usually DiscreteFeature::Value can be easily defined using
keyword_set!.
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
discrete features use the other two productions.
Given this, this trait parses as:
<feature-name>
│├─ <ident> ─┤│
<discrete-feature>
│├─ "(" ─╮─ <feature-name> ─ ":" ─ <value> ─╭─ ")" ─┤│
╰─ <feature-name> ─────────────────╯
Required Associated Types§
Provided Methods§
fn parse_descrete_feature( p: &mut Parser<'a>, name: &'static str, ) -> Result<(LeftParen, Ident, Option<(Colon, Self::Value)>, 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.