pub trait RuleVariants<'a>:
Sized
+ ToCursors
+ ToSpan {
type DeclarationValue: DeclarationValue<'a, Self::Metadata>;
type Metadata: NodeMetadata;
// Provided methods
fn parse_at_rule<I>(p: &mut Parser<'a, I>, _name: Cursor) -> Result<Self>
where I: Iterator<Item = Cursor> + Clone { ... }
fn parse_unknown_at_rule<I>(
p: &mut Parser<'a, I>,
_name: Cursor,
) -> Result<Self>
where I: Iterator<Item = Cursor> + Clone { ... }
fn parse_qualified_rule<I>(
p: &mut Parser<'a, I>,
_name: Cursor,
) -> Result<Self>
where I: Iterator<Item = Cursor> + Clone { ... }
fn parse_unknown_qualified_rule<I>(
p: &mut Parser<'a, I>,
_name: Cursor,
) -> Result<Self>
where I: Iterator<Item = Cursor> + Clone { ... }
fn bad_declaration(_: BadDeclaration<'a>) -> Option<Self> { ... }
fn is_unknown(&self) -> bool { ... }
fn from_declaration_group(
_group: DeclarationGroup<'a, Self::DeclarationValue, Self::Metadata>,
) -> Option<Self> { ... }
fn parse_rule_variants<I>(p: &mut Parser<'a, I>) -> Result<Self>
where I: Iterator<Item = Cursor> + Clone { ... }
}Expand description
A trait that can be used for AST nodes representing a Declaration’s Value. It offers some convenience functions for handling such values.
Required Associated Types§
Sourcetype DeclarationValue: DeclarationValue<'a, Self::Metadata>
type DeclarationValue: DeclarationValue<'a, Self::Metadata>
The declaration value type used when converting declaration groups to rules.
Sourcetype Metadata: NodeMetadata
type Metadata: NodeMetadata
The metadata type used when converting declaration groups to rules.
Provided Methods§
Sourcefn parse_at_rule<I>(p: &mut Parser<'a, I>, _name: Cursor) -> Result<Self>
fn parse_at_rule<I>(p: &mut Parser<'a, I>, _name: Cursor) -> Result<Self>
Like crate::Parse::parse() but with the additional context of the name Cursor. This cursor is known to be
an AtKeyword, therefore this should return a Self reflecting a AtRule. If the
AtRule is not known, or otherwise fails then this should Err and RuleVariants::parse_unknown_at_rule() can
be called.
The default implementation of this method is to return an Unexpected Err.
Sourcefn parse_unknown_at_rule<I>(
p: &mut Parser<'a, I>,
_name: Cursor,
) -> Result<Self>
fn parse_unknown_at_rule<I>( p: &mut Parser<'a, I>, _name: Cursor, ) -> Result<Self>
Like crate::Parse::parse() but with the additional context of the name Cursor. This cursor is known to be
an AtKeyword and that RuleVariants::parse_at_rule() failed. This should therefore return a Self that represents
an Unknown AtRule, or otherwise Err.
The default implementation of this method is to return an Unexpected Err.
Sourcefn parse_qualified_rule<I>(p: &mut Parser<'a, I>, _name: Cursor) -> Result<Self>
fn parse_qualified_rule<I>(p: &mut Parser<'a, I>, _name: Cursor) -> Result<Self>
Like crate::Parse::parse() but with the additional context that the next cursor is not an AtKeyword, therefore this can attempt to parse a Qualified Rule. If the rule fails to parse, then RuleVariants::parse_unknown_qualified_rule() will be called.
The default implementation of this method is to return an Unexpected Err.
Sourcefn parse_unknown_qualified_rule<I>(
p: &mut Parser<'a, I>,
_name: Cursor,
) -> Result<Self>
fn parse_unknown_qualified_rule<I>( p: &mut Parser<'a, I>, _name: Cursor, ) -> Result<Self>
Like crate::Parse::parse() but with the additional context that the next cursor is not an AtKeyword, and that RuleVariants::parse_qualified_rule() has failed. Therefore this should attempt to parse an Unknown Qualified Rule, or Err.
The default implementation of this method is to return an Unexpected Err.
Sourcefn bad_declaration(_: BadDeclaration<'a>) -> Option<Self>
fn bad_declaration(_: BadDeclaration<'a>) -> Option<Self>
If all of the parse steps have failed, including parsing the Unknown Qualified Rule, we may want to consume a bad declaration (especially if the parser is in a nested context). This is done automatically on failing to parse an Unknown Qualified Rule, and this method is given the BadDeclaration.
This should attempt to build a Self that represents the BadDeclaration, or return None so RuleVariants::parse_rule_variants() can Err.
The default implementation of this method is to return None.
Sourcefn is_unknown(&self) -> bool
fn is_unknown(&self) -> bool
Determines if the parsed Self was parsed as an unknown rule (UnknownAtRule or UnknownQualifiedRule).
This is used to distinguish between known rules (like @media, @supports, style rules) and unknown rules. When disambiguating between declarations and rules, known rules should be preferred over unknown declarations, but unknown declarations should be preferred over unknown rules.
The default implementation returns false, assuming all rules are known.
Sourcefn from_declaration_group(
_group: DeclarationGroup<'a, Self::DeclarationValue, Self::Metadata>,
) -> Option<Self>
fn from_declaration_group( _group: DeclarationGroup<'a, Self::DeclarationValue, Self::Metadata>, ) -> Option<Self>
Creates a rule variant from a group of declarations.
Per CSS Syntax § 5.4.4, blocks can contain interleaved declarations and rules. This method allows wrapping groups of declarations as a rule variant for storage in the rules list.
Returns None if this rule type doesn’t support declaration interleaving.
fn parse_rule_variants<I>(p: &mut Parser<'a, I>) -> 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.