@@ -105,6 +105,8 @@ impl Error for PropertiesError {
105
105
& self . description
106
106
}
107
107
108
+ // The "readable" version is less readable, especially since it requires manual type assertions.
109
+ #[ allow( clippy:: manual_map) ]
108
110
fn source ( & self ) -> Option < & ( dyn Error + ' static ) > {
109
111
match self . cause {
110
112
Some ( ref c) => Some ( c. deref ( ) ) ,
@@ -324,12 +326,6 @@ impl Line {
324
326
}
325
327
}
326
328
327
- impl Into < LineContent > for Line {
328
- fn into ( self ) -> LineContent {
329
- self . data
330
- }
331
- }
332
-
333
329
impl Display for Line {
334
330
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
335
331
write ! ( f, "Line {{line_number: {}, content: {}}}" , self . line_number, self . data)
@@ -348,13 +344,19 @@ pub enum LineContent {
348
344
349
345
impl Display for LineContent {
350
346
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
351
- match self {
352
- & LineContent :: Comment ( ref s) => write ! ( f, "Comment({:?})" , s) ,
353
- & LineContent :: KVPair ( ref k, ref v) => write ! ( f, "KVPair({:?}, {:?})" , k, v) ,
347
+ match * self {
348
+ LineContent :: Comment ( ref s) => write ! ( f, "Comment({:?})" , s) ,
349
+ LineContent :: KVPair ( ref k, ref v) => write ! ( f, "KVPair({:?}, {:?})" , k, v) ,
354
350
}
355
351
}
356
352
}
357
353
354
+ impl From < Line > for LineContent {
355
+ fn from ( line : Line ) -> LineContent {
356
+ line. data
357
+ }
358
+ }
359
+
358
360
//github.com///github.com///github.com///github.com///github.com///github.com///github.com/
359
361
360
362
fn unescape ( s : & str , line_number : usize ) -> Result < String , PropertiesError > {
@@ -440,15 +442,15 @@ lazy_static! {
440
442
" ) . unwrap( ) ;
441
443
}
442
444
443
- fn parse_line < ' a > ( line : & ' a str ) -> Option < ParsedLine < ' a > > {
445
+ fn parse_line ( line : & str ) -> Option < ParsedLine > {
444
446
if let Some ( c) = LINE_RE . captures ( line) {
445
447
if let Some ( comment_match) = c. get ( 1 ) {
446
448
Some ( ParsedLine :: Comment ( comment_match. as_str ( ) ) )
447
449
} else if let Some ( key_match) = c. get ( 2 ) {
448
450
let key = key_match. as_str ( ) ;
449
451
if let Some ( value_match) = c. get ( 3 ) {
450
452
Some ( ParsedLine :: KVPair ( key, value_match. as_str ( ) ) )
451
- } else if key != "" {
453
+ } else if !key . is_empty ( ) {
452
454
Some ( ParsedLine :: KVPair ( key, "" ) )
453
455
} else {
454
456
None
@@ -524,9 +526,8 @@ impl<R: Read> Iterator for PropertiesIter<R> {
524
526
fn next ( & mut self ) -> Option < Self :: Item > {
525
527
loop {
526
528
match self . lines . next ( ) {
527
- Some ( Ok ( LogicalLine ( line_no, line) ) ) => match parse_line ( & line) {
528
- Some ( parsed_line) => return Some ( self . parsed_line_to_line ( parsed_line, line_no) ) ,
529
- None => ( ) , // empty line, continue
529
+ Some ( Ok ( LogicalLine ( line_no, line) ) ) => if let Some ( parsed_line) = parse_line ( & line) {
530
+ return Some ( self . parsed_line_to_line ( parsed_line, line_no) ) ;
530
531
} ,
531
532
Some ( Err ( e) ) => return Some ( Err ( e) ) ,
532
533
None => return None ,
@@ -554,15 +555,17 @@ pub enum LineEnding {
554
555
//github.com/ Line feed alone.
555
556
LF ,
556
557
//github.com/ Carriage return followed by line feed.
558
+ // The name can't be changed without breaking backward compatibility.
559
+ #[ allow( clippy:: upper_case_acronyms) ]
557
560
CRLF ,
558
561
}
559
562
560
563
impl Display for LineEnding {
561
564
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
562
- f. write_str ( match self {
563
- & LineEnding :: CR => "LineEnding::CR" ,
564
- & LineEnding :: LF => "LineEnding::LF" ,
565
- & LineEnding :: CRLF => "LineEnding::CRLF" ,
565
+ f. write_str ( match * self {
566
+ LineEnding :: CR => "LineEnding::CR" ,
567
+ LineEnding :: LF => "LineEnding::LF" ,
568
+ LineEnding :: CRLF => "LineEnding::CRLF" ,
566
569
} )
567
570
}
568
571
}
0 commit comments