@@ -3,6 +3,32 @@ use structs::display_list::{DisplayAnnotationType, DisplayLine, DisplayList, Dis
33 DisplaySnippetType } ;
44use structs:: formatted_display_list:: { FormattedDisplayLine , FormattedDisplayList } ;
55
6+ struct DisplayListFormatting { }
7+
8+ impl DisplayListFormatting {
9+ fn format_snippet_type ( snippet_type : & DisplaySnippetType ) -> String {
10+ match snippet_type {
11+ DisplaySnippetType :: Error => "error" . to_string ( ) ,
12+ DisplaySnippetType :: Warning => "warning" . to_string ( ) ,
13+ }
14+ }
15+
16+ fn format_inline_marks ( inline_marks : & [ DisplayMark ] , inline_marks_width : usize ) -> String {
17+ format ! (
18+ "{: >width$}" ,
19+ inline_marks
20+ . iter( )
21+ . map( |mark| match mark {
22+ DisplayMark :: AnnotationThrough => "|" ,
23+ DisplayMark :: AnnotationStart => "/" ,
24+ } )
25+ . collect:: <Vec <& str >>( )
26+ . join( "" ) ,
27+ width = inline_marks_width
28+ )
29+ }
30+ }
31+
632impl fmt:: Display for DisplayList {
733 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
834 let lineno_width = self . body . iter ( ) . fold ( 0 , |max, line| match line {
@@ -59,7 +85,7 @@ impl FormattedDisplayLine {
5985 label,
6086 } => FormattedDisplayLine :: Raw ( format ! (
6187 "{}[{}]: {}" ,
62- Self :: format_snippet_type( & snippet_type) ,
88+ DisplayListFormatting :: format_snippet_type( & snippet_type) ,
6389 id,
6490 label
6591 ) ) ,
@@ -80,7 +106,7 @@ impl FormattedDisplayLine {
80106 ..
81107 } => FormattedDisplayLine :: Source {
82108 lineno : format ! ( "{: >width$}" , lineno, width = lineno_width) ,
83- inline_marks : Self :: format_inline_marks ( & inline_marks, inline_marks_width) ,
109+ inline_marks : DisplayListFormatting :: format_inline_marks ( & inline_marks, inline_marks_width) ,
84110 content,
85111 } ,
86112 DisplayLine :: Annotation {
@@ -90,35 +116,13 @@ impl FormattedDisplayLine {
90116 annotation_type,
91117 } => FormattedDisplayLine :: Annotation {
92118 lineno : " " . repeat ( lineno_width) ,
93- inline_marks : Self :: format_inline_marks ( & inline_marks, inline_marks_width) ,
119+ inline_marks : DisplayListFormatting :: format_inline_marks ( & inline_marks, inline_marks_width) ,
94120 content : Self :: format_annotation_content ( range, & label, & annotation_type) ,
95121 } ,
96122 DisplayLine :: Fold => FormattedDisplayLine :: Fold ,
97123 }
98124 }
99125
100- fn format_snippet_type ( snippet_type : & DisplaySnippetType ) -> String {
101- match snippet_type {
102- DisplaySnippetType :: Error => "error" . to_string ( ) ,
103- DisplaySnippetType :: Warning => "warning" . to_string ( ) ,
104- }
105- }
106-
107- fn format_inline_marks ( inline_marks : & [ DisplayMark ] , inline_marks_width : usize ) -> String {
108- format ! (
109- "{: >width$}" ,
110- inline_marks
111- . iter( )
112- . map( |mark| match mark {
113- DisplayMark :: AnnotationThrough => "|" ,
114- DisplayMark :: AnnotationStart => "/" ,
115- } )
116- . collect:: <Vec <& str >>( )
117- . join( "" ) ,
118- width = inline_marks_width
119- )
120- }
121-
122126 fn format_annotation_content (
123127 range : ( usize , usize ) ,
124128 label : & Option < String > ,
0 commit comments