@@ -18,20 +18,21 @@ impl ast::Comment {
18
18
}
19
19
20
20
pub fn prefix ( & self ) -> & ' static str {
21
- let & ( prefix, _kind) = CommentKind :: with_prefix_from_text ( self . text ( ) ) ;
21
+ let & ( prefix, _kind) = CommentKind :: BY_PREFIX
22
+ . iter ( )
23
+ . find ( |& ( prefix, kind) | self . kind ( ) == * kind && self . text ( ) . starts_with ( prefix) )
24
+ . unwrap ( ) ;
22
25
prefix
23
26
}
24
27
25
- pub fn kind_and_prefix ( & self ) -> & ( & ' static str , CommentKind ) {
26
- CommentKind :: with_prefix_from_text ( self . text ( ) )
27
- }
28
-
29
28
/// Returns the textual content of a doc comment block as a single string.
30
29
/// That is, strips leading `///` (+ optional 1 character of whitespace),
31
30
/// trailing `*/`, trailing whitespace and then joins the lines.
32
31
pub fn doc_comment ( & self ) -> Option < & str > {
33
- match self . kind_and_prefix ( ) {
34
- ( prefix, CommentKind { shape, doc : Some ( _) } ) => {
32
+ let kind = self . kind ( ) ;
33
+ match kind {
34
+ CommentKind { shape, doc : Some ( _) } => {
35
+ let prefix = kind. prefix ( ) ;
35
36
let text = & self . text ( ) . as_str ( ) [ prefix. len ( ) ..] ;
36
37
let ws = text. chars ( ) . next ( ) . filter ( |c| c. is_whitespace ( ) ) ;
37
38
let text = ws. map_or ( text, |ws| & text[ ws. len_utf8 ( ) ..] ) ;
@@ -88,12 +89,16 @@ impl CommentKind {
88
89
] ;
89
90
90
91
pub ( crate ) fn from_text ( text : & str ) -> CommentKind {
91
- let & ( _prefix, kind) = Self :: with_prefix_from_text ( text) ;
92
+ let & ( _prefix, kind) = CommentKind :: BY_PREFIX
93
+ . iter ( )
94
+ . find ( |& ( prefix, _kind) | text. starts_with ( prefix) )
95
+ . unwrap ( ) ;
92
96
kind
93
97
}
94
98
95
- fn with_prefix_from_text ( text : & str ) -> & ( & ' static str , CommentKind ) {
96
- CommentKind :: BY_PREFIX . iter ( ) . find ( |& ( prefix, _kind) | text. starts_with ( prefix) ) . unwrap ( )
99
+ fn prefix ( & self ) -> & ' static str {
100
+ let & ( prefix, _) = CommentKind :: BY_PREFIX . iter ( ) . find ( |( _, kind) | kind == self ) . unwrap ( ) ;
101
+ prefix
97
102
}
98
103
}
99
104
0 commit comments