11pub struct CSSRuleListParser ;
22pub ( crate ) struct CSSDeclarationListParser ;
33
4- pub type Declaration = ( String , String ) ;
5- pub type QualifiedRule = ( String , Vec < Declaration > ) ;
4+ pub type Declaration < ' i > = ( cssparser :: CowRcStr < ' i > , & ' i str ) ;
5+ pub type QualifiedRule < ' i > = ( & ' i str , Vec < Declaration < ' i > > ) ;
66
7- fn exhaust ( input : & mut cssparser:: Parser ) -> String {
7+ fn exhaust < ' i > ( input : & mut cssparser:: Parser < ' i , ' _ > ) -> & ' i str {
88 let start = input. position ( ) ;
99 while input. next ( ) . is_ok ( ) { }
10- input. slice_from ( start) . to_string ( )
10+ input. slice_from ( start)
1111}
1212
1313/// Parser for qualified rules - a prelude + a simple {} block.
1414///
1515/// Usually these rules are a selector + list of declarations: `p { color: blue; font-size: 2px }`
1616impl < ' i > cssparser:: QualifiedRuleParser < ' i > for CSSRuleListParser {
17- type Prelude = String ;
18- type QualifiedRule = QualifiedRule ;
17+ type Prelude = & ' i str ;
18+ type QualifiedRule = QualifiedRule < ' i > ;
1919 type Error = ( ) ;
2020
2121 fn parse_prelude < ' t > (
@@ -48,31 +48,31 @@ impl<'i> cssparser::QualifiedRuleParser<'i> for CSSRuleListParser {
4848
4949/// Parse a declaration within {} block: `color: blue`
5050impl < ' i > cssparser:: DeclarationParser < ' i > for CSSDeclarationListParser {
51- type Declaration = Declaration ;
51+ type Declaration = Declaration < ' i > ;
5252 type Error = ( ) ;
5353
5454 fn parse_value < ' t > (
5555 & mut self ,
5656 name : cssparser:: CowRcStr < ' i > ,
5757 input : & mut cssparser:: Parser < ' i , ' t > ,
5858 ) -> Result < Self :: Declaration , cssparser:: ParseError < ' i , Self :: Error > > {
59- Ok ( ( name. to_string ( ) , exhaust ( input) ) )
59+ Ok ( ( name, exhaust ( input) ) )
6060 }
6161}
6262
63- impl cssparser:: AtRuleParser < ' _ > for CSSRuleListParser {
63+ impl < ' i > cssparser:: AtRuleParser < ' i > for CSSRuleListParser {
6464 type PreludeNoBlock = String ;
6565 type PreludeBlock = String ;
66- type AtRule = QualifiedRule ;
66+ type AtRule = QualifiedRule < ' i > ;
6767 type Error = ( ) ;
6868}
6969
7070/// Parsing for at-rules, e.g: `@charset "utf-8";`
7171/// Since they are can not be inlined we use the default implementation, that rejects all at-rules.
72- impl cssparser:: AtRuleParser < ' _ > for CSSDeclarationListParser {
72+ impl < ' i > cssparser:: AtRuleParser < ' i > for CSSDeclarationListParser {
7373 type PreludeNoBlock = String ;
7474 type PreludeBlock = String ;
75- type AtRule = Declaration ;
75+ type AtRule = Declaration < ' i > ;
7676 type Error = ( ) ;
7777}
7878
@@ -81,12 +81,14 @@ pub struct CSSParser<'i, 't> {
8181}
8282
8383impl < ' i : ' t , ' t > CSSParser < ' i , ' t > {
84+ #[ inline]
8485 pub fn new ( css : & ' t mut cssparser:: ParserInput < ' i > ) -> CSSParser < ' i , ' t > {
8586 CSSParser {
8687 input : cssparser:: Parser :: new ( css) ,
8788 }
8889 }
8990
91+ #[ inline]
9092 pub fn parse < ' a > ( & ' a mut self ) -> cssparser:: RuleListParser < ' i , ' t , ' a , CSSRuleListParser > {
9193 cssparser:: RuleListParser :: new_for_stylesheet ( & mut self . input , CSSRuleListParser )
9294 }
0 commit comments