@@ -25,7 +25,7 @@ fn is_custom_comment(comment: &str) -> bool {
25
25
}
26
26
27
27
#[ derive( Copy , Clone , PartialEq , Eq ) ]
28
- pub enum CommentStyle < ' a > {
28
+ pub ( crate ) enum CommentStyle < ' a > {
29
29
DoubleSlash ,
30
30
TripleSlash ,
31
31
Doc ,
@@ -45,7 +45,7 @@ fn custom_opener(s: &str) -> &str {
45
45
46
46
impl < ' a > CommentStyle < ' a > {
47
47
/// Returns `true` if the commenting style covers a line only.
48
- pub fn is_line_comment ( & self ) -> bool {
48
+ pub ( crate ) fn is_line_comment ( & self ) -> bool {
49
49
match * self {
50
50
CommentStyle :: DoubleSlash
51
51
| CommentStyle :: TripleSlash
@@ -56,7 +56,7 @@ impl<'a> CommentStyle<'a> {
56
56
}
57
57
58
58
/// Returns `true` if the commenting style can span over multiple lines.
59
- pub fn is_block_comment ( & self ) -> bool {
59
+ pub ( crate ) fn is_block_comment ( & self ) -> bool {
60
60
match * self {
61
61
CommentStyle :: SingleBullet | CommentStyle :: DoubleBullet | CommentStyle :: Exclamation => {
62
62
true
@@ -66,14 +66,14 @@ impl<'a> CommentStyle<'a> {
66
66
}
67
67
68
68
/// Returns `true` if the commenting style is for documentation.
69
- pub fn is_doc_comment ( & self ) -> bool {
69
+ pub ( crate ) fn is_doc_comment ( & self ) -> bool {
70
70
match * self {
71
71
CommentStyle :: TripleSlash | CommentStyle :: Doc => true ,
72
72
_ => false ,
73
73
}
74
74
}
75
75
76
- pub fn opener ( & self ) -> & ' a str {
76
+ pub ( crate ) fn opener ( & self ) -> & ' a str {
77
77
match * self {
78
78
CommentStyle :: DoubleSlash => "// " ,
79
79
CommentStyle :: TripleSlash => "/// " ,
@@ -85,7 +85,7 @@ impl<'a> CommentStyle<'a> {
85
85
}
86
86
}
87
87
88
- pub fn closer ( & self ) -> & ' a str {
88
+ pub ( crate ) fn closer ( & self ) -> & ' a str {
89
89
match * self {
90
90
CommentStyle :: DoubleSlash
91
91
| CommentStyle :: TripleSlash
@@ -96,7 +96,7 @@ impl<'a> CommentStyle<'a> {
96
96
}
97
97
}
98
98
99
- pub fn line_start ( & self ) -> & ' a str {
99
+ pub ( crate ) fn line_start ( & self ) -> & ' a str {
100
100
match * self {
101
101
CommentStyle :: DoubleSlash => "// " ,
102
102
CommentStyle :: TripleSlash => "/// " ,
@@ -107,7 +107,7 @@ impl<'a> CommentStyle<'a> {
107
107
}
108
108
}
109
109
110
- pub fn to_str_tuplet ( & self ) -> ( & ' a str , & ' a str , & ' a str ) {
110
+ pub ( crate ) fn to_str_tuplet ( & self ) -> ( & ' a str , & ' a str , & ' a str ) {
111
111
( self . opener ( ) , self . closer ( ) , self . line_start ( ) )
112
112
}
113
113
}
@@ -143,7 +143,7 @@ fn comment_style(orig: &str, normalize_comments: bool) -> CommentStyle<'_> {
143
143
}
144
144
145
145
/// Returns true if the last line of the passed string finishes with a block-comment.
146
- pub fn is_last_comment_block ( s : & str ) -> bool {
146
+ pub ( crate ) fn is_last_comment_block ( s : & str ) -> bool {
147
147
s. trim_end ( ) . ends_with ( "*/" )
148
148
}
149
149
@@ -152,7 +152,7 @@ pub fn is_last_comment_block(s: &str) -> bool {
152
152
/// recovered. If `allow_extend` is true and there is no comment between the two
153
153
/// strings, then they will be put on a single line as long as doing so does not
154
154
/// exceed max width.
155
- pub fn combine_strs_with_missing_comments (
155
+ pub ( crate ) fn combine_strs_with_missing_comments (
156
156
context : & RewriteContext < ' _ > ,
157
157
prev_str : & str ,
158
158
next_str : & str ,
@@ -239,11 +239,11 @@ pub fn combine_strs_with_missing_comments(
239
239
Some ( result)
240
240
}
241
241
242
- pub fn rewrite_doc_comment ( orig : & str , shape : Shape , config : & Config ) -> Option < String > {
242
+ pub ( crate ) fn rewrite_doc_comment ( orig : & str , shape : Shape , config : & Config ) -> Option < String > {
243
243
identify_comment ( orig, false , shape, config, true )
244
244
}
245
245
246
- pub fn rewrite_comment (
246
+ pub ( crate ) fn rewrite_comment (
247
247
orig : & str ,
248
248
block_style : bool ,
249
249
shape : Shape ,
@@ -845,7 +845,7 @@ fn has_url(s: &str) -> bool {
845
845
846
846
/// Given the span, rewrite the missing comment inside it if available.
847
847
/// Note that the given span must only include comments (or leading/trailing whitespaces).
848
- pub fn rewrite_missing_comment (
848
+ pub ( crate ) fn rewrite_missing_comment (
849
849
span : Span ,
850
850
shape : Shape ,
851
851
context : & RewriteContext < ' _ > ,
@@ -862,7 +862,7 @@ pub fn rewrite_missing_comment(
862
862
/// Recover the missing comments in the specified span, if available.
863
863
/// The layout of the comments will be preserved as long as it does not break the code
864
864
/// and its total width does not exceed the max width.
865
- pub fn recover_missing_comment_in_span (
865
+ pub ( crate ) fn recover_missing_comment_in_span (
866
866
span : Span ,
867
867
shape : Shape ,
868
868
context : & RewriteContext < ' _ > ,
@@ -964,7 +964,7 @@ fn left_trim_comment_line<'a>(line: &'a str, style: &CommentStyle<'_>) -> (&'a s
964
964
}
965
965
}
966
966
967
- pub trait FindUncommented {
967
+ pub ( crate ) trait FindUncommented {
968
968
fn find_uncommented ( & self , pat : & str ) -> Option < usize > ;
969
969
}
970
970
@@ -997,7 +997,7 @@ impl FindUncommented for str {
997
997
// is expected to be prefixed by a comment, including delimiters.
998
998
// Good: `/* /* inner */ outer */ code();`
999
999
// Bad: `code(); // hello\n world!`
1000
- pub fn find_comment_end ( s : & str ) -> Option < usize > {
1000
+ pub ( crate ) fn find_comment_end ( s : & str ) -> Option < usize > {
1001
1001
let mut iter = CharClasses :: new ( s. char_indices ( ) ) ;
1002
1002
for ( kind, ( i, _c) ) in & mut iter {
1003
1003
if kind == FullCodeCharKind :: Normal || kind == FullCodeCharKind :: InString {
@@ -1014,11 +1014,11 @@ pub fn find_comment_end(s: &str) -> Option<usize> {
1014
1014
}
1015
1015
1016
1016
/// Returns `true` if text contains any comment.
1017
- pub fn contains_comment ( text : & str ) -> bool {
1017
+ pub ( crate ) fn contains_comment ( text : & str ) -> bool {
1018
1018
CharClasses :: new ( text. chars ( ) ) . any ( |( kind, _) | kind. is_comment ( ) )
1019
1019
}
1020
1020
1021
- pub struct CharClasses < T >
1021
+ pub ( crate ) struct CharClasses < T >
1022
1022
where
1023
1023
T : Iterator ,
1024
1024
T :: Item : RichChar ,
@@ -1027,7 +1027,7 @@ where
1027
1027
status : CharClassesStatus ,
1028
1028
}
1029
1029
1030
- pub trait RichChar {
1030
+ pub ( crate ) trait RichChar {
1031
1031
fn get_char ( & self ) -> char ;
1032
1032
}
1033
1033
@@ -1073,7 +1073,7 @@ enum CharClassesStatus {
1073
1073
1074
1074
/// Distinguish between functional part of code and comments
1075
1075
#[ derive( PartialEq , Eq , Debug , Clone , Copy ) ]
1076
- pub enum CodeCharKind {
1076
+ pub ( crate ) enum CodeCharKind {
1077
1077
Normal ,
1078
1078
Comment ,
1079
1079
}
@@ -1082,7 +1082,7 @@ pub enum CodeCharKind {
1082
1082
/// describing opening and closing of comments for ease when chunking
1083
1083
/// code from tagged characters
1084
1084
#[ derive( PartialEq , Eq , Debug , Clone , Copy ) ]
1085
- pub enum FullCodeCharKind {
1085
+ pub ( crate ) enum FullCodeCharKind {
1086
1086
Normal ,
1087
1087
/// The first character of a comment, there is only one for a comment (always '/')
1088
1088
StartComment ,
@@ -1106,7 +1106,7 @@ pub enum FullCodeCharKind {
1106
1106
}
1107
1107
1108
1108
impl FullCodeCharKind {
1109
- pub fn is_comment ( self ) -> bool {
1109
+ pub ( crate ) fn is_comment ( self ) -> bool {
1110
1110
match self {
1111
1111
FullCodeCharKind :: StartComment
1112
1112
| FullCodeCharKind :: InComment
@@ -1119,7 +1119,7 @@ impl FullCodeCharKind {
1119
1119
}
1120
1120
1121
1121
/// Returns true if the character is inside a comment
1122
- pub fn inside_comment ( self ) -> bool {
1122
+ pub ( crate ) fn inside_comment ( self ) -> bool {
1123
1123
match self {
1124
1124
FullCodeCharKind :: InComment
1125
1125
| FullCodeCharKind :: StartStringCommented
@@ -1129,12 +1129,12 @@ impl FullCodeCharKind {
1129
1129
}
1130
1130
}
1131
1131
1132
- pub fn is_string ( self ) -> bool {
1132
+ pub ( crate ) fn is_string ( self ) -> bool {
1133
1133
self == FullCodeCharKind :: InString || self == FullCodeCharKind :: StartString
1134
1134
}
1135
1135
1136
1136
/// Returns true if the character is within a commented string
1137
- pub fn is_commented_string ( self ) -> bool {
1137
+ pub ( crate ) fn is_commented_string ( self ) -> bool {
1138
1138
self == FullCodeCharKind :: InStringCommented
1139
1139
|| self == FullCodeCharKind :: StartStringCommented
1140
1140
}
@@ -1153,7 +1153,7 @@ where
1153
1153
T : Iterator ,
1154
1154
T :: Item : RichChar ,
1155
1155
{
1156
- pub fn new ( base : T ) -> CharClasses < T > {
1156
+ pub ( crate ) fn new ( base : T ) -> CharClasses < T > {
1157
1157
CharClasses {
1158
1158
base : multipeek ( base) ,
1159
1159
status : CharClassesStatus :: Normal ,
@@ -1336,13 +1336,13 @@ where
1336
1336
1337
1337
/// An iterator over the lines of a string, paired with the char kind at the
1338
1338
/// end of the line.
1339
- pub struct LineClasses < ' a > {
1339
+ pub ( crate ) struct LineClasses < ' a > {
1340
1340
base : iter:: Peekable < CharClasses < std:: str:: Chars < ' a > > > ,
1341
1341
kind : FullCodeCharKind ,
1342
1342
}
1343
1343
1344
1344
impl < ' a > LineClasses < ' a > {
1345
- pub fn new ( s : & ' a str ) -> Self {
1345
+ pub ( crate ) fn new ( s : & ' a str ) -> Self {
1346
1346
LineClasses {
1347
1347
base : CharClasses :: new ( s. chars ( ) ) . peekable ( ) ,
1348
1348
kind : FullCodeCharKind :: Normal ,
@@ -1458,14 +1458,14 @@ impl<'a> Iterator for UngroupedCommentCodeSlices<'a> {
1458
1458
/// Iterator over an alternating sequence of functional and commented parts of
1459
1459
/// a string. The first item is always a, possibly zero length, subslice of
1460
1460
/// functional text. Line style comments contain their ending newlines.
1461
- pub struct CommentCodeSlices < ' a > {
1461
+ pub ( crate ) struct CommentCodeSlices < ' a > {
1462
1462
slice : & ' a str ,
1463
1463
last_slice_kind : CodeCharKind ,
1464
1464
last_slice_end : usize ,
1465
1465
}
1466
1466
1467
1467
impl < ' a > CommentCodeSlices < ' a > {
1468
- pub fn new ( slice : & ' a str ) -> CommentCodeSlices < ' a > {
1468
+ pub ( crate ) fn new ( slice : & ' a str ) -> CommentCodeSlices < ' a > {
1469
1469
CommentCodeSlices {
1470
1470
slice,
1471
1471
last_slice_kind : CodeCharKind :: Comment ,
@@ -1536,7 +1536,7 @@ impl<'a> Iterator for CommentCodeSlices<'a> {
1536
1536
1537
1537
/// Checks is `new` didn't miss any comment from `span`, if it removed any, return previous text
1538
1538
/// (if it fits in the width/offset, else return `None`), else return `new`
1539
- pub fn recover_comment_removed (
1539
+ pub ( crate ) fn recover_comment_removed (
1540
1540
new : String ,
1541
1541
span : Span ,
1542
1542
context : & RewriteContext < ' _ > ,
@@ -1560,7 +1560,7 @@ pub fn recover_comment_removed(
1560
1560
}
1561
1561
}
1562
1562
1563
- pub fn filter_normal_code ( code : & str ) -> String {
1563
+ pub ( crate ) fn filter_normal_code ( code : & str ) -> String {
1564
1564
let mut buffer = String :: with_capacity ( code. len ( ) ) ;
1565
1565
LineClasses :: new ( code) . for_each ( |( kind, line) | match kind {
1566
1566
FullCodeCharKind :: Normal
0 commit comments