1
1
pub struct CSSRuleListParser ;
2
2
pub ( crate ) struct CSSDeclarationListParser ;
3
3
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 > > ) ;
6
6
7
- fn exhaust ( input : & mut cssparser:: Parser ) -> String {
7
+ fn exhaust < ' i > ( input : & mut cssparser:: Parser < ' i , ' _ > ) -> & ' i str {
8
8
let start = input. position ( ) ;
9
9
while input. next ( ) . is_ok ( ) { }
10
- input. slice_from ( start) . to_string ( )
10
+ input. slice_from ( start)
11
11
}
12
12
13
13
/// Parser for qualified rules - a prelude + a simple {} block.
14
14
///
15
15
/// Usually these rules are a selector + list of declarations: `p { color: blue; font-size: 2px }`
16
16
impl < ' i > cssparser:: QualifiedRuleParser < ' i > for CSSRuleListParser {
17
- type Prelude = String ;
18
- type QualifiedRule = QualifiedRule ;
17
+ type Prelude = & ' i str ;
18
+ type QualifiedRule = QualifiedRule < ' i > ;
19
19
type Error = ( ) ;
20
20
21
21
fn parse_prelude < ' t > (
@@ -48,31 +48,31 @@ impl<'i> cssparser::QualifiedRuleParser<'i> for CSSRuleListParser {
48
48
49
49
/// Parse a declaration within {} block: `color: blue`
50
50
impl < ' i > cssparser:: DeclarationParser < ' i > for CSSDeclarationListParser {
51
- type Declaration = Declaration ;
51
+ type Declaration = Declaration < ' i > ;
52
52
type Error = ( ) ;
53
53
54
54
fn parse_value < ' t > (
55
55
& mut self ,
56
56
name : cssparser:: CowRcStr < ' i > ,
57
57
input : & mut cssparser:: Parser < ' i , ' t > ,
58
58
) -> Result < Self :: Declaration , cssparser:: ParseError < ' i , Self :: Error > > {
59
- Ok ( ( name. to_string ( ) , exhaust ( input) ) )
59
+ Ok ( ( name, exhaust ( input) ) )
60
60
}
61
61
}
62
62
63
- impl cssparser:: AtRuleParser < ' _ > for CSSRuleListParser {
63
+ impl < ' i > cssparser:: AtRuleParser < ' i > for CSSRuleListParser {
64
64
type PreludeNoBlock = String ;
65
65
type PreludeBlock = String ;
66
- type AtRule = QualifiedRule ;
66
+ type AtRule = QualifiedRule < ' i > ;
67
67
type Error = ( ) ;
68
68
}
69
69
70
70
/// Parsing for at-rules, e.g: `@charset "utf-8";`
71
71
/// 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 {
73
73
type PreludeNoBlock = String ;
74
74
type PreludeBlock = String ;
75
- type AtRule = Declaration ;
75
+ type AtRule = Declaration < ' i > ;
76
76
type Error = ( ) ;
77
77
}
78
78
@@ -81,12 +81,14 @@ pub struct CSSParser<'i, 't> {
81
81
}
82
82
83
83
impl < ' i : ' t , ' t > CSSParser < ' i , ' t > {
84
+ #[ inline]
84
85
pub fn new ( css : & ' t mut cssparser:: ParserInput < ' i > ) -> CSSParser < ' i , ' t > {
85
86
CSSParser {
86
87
input : cssparser:: Parser :: new ( css) ,
87
88
}
88
89
}
89
90
91
+ #[ inline]
90
92
pub fn parse < ' a > ( & ' a mut self ) -> cssparser:: RuleListParser < ' i , ' t , ' a , CSSRuleListParser > {
91
93
cssparser:: RuleListParser :: new_for_stylesheet ( & mut self . input , CSSRuleListParser )
92
94
}
0 commit comments