@@ -165,10 +165,10 @@ impl DiagnosticStyledString {
165
165
DiagnosticStyledString ( vec ! [ ] )
166
166
}
167
167
pub fn push_normal < S : Into < String > > ( & mut self , t : S ) {
168
- self . 0 . push ( StringPart :: Normal ( t. into ( ) ) ) ;
168
+ self . 0 . push ( StringPart :: normal ( t. into ( ) ) ) ;
169
169
}
170
170
pub fn push_highlighted < S : Into < String > > ( & mut self , t : S ) {
171
- self . 0 . push ( StringPart :: Highlighted ( t. into ( ) ) ) ;
171
+ self . 0 . push ( StringPart :: highlighted ( t. into ( ) ) ) ;
172
172
}
173
173
pub fn push < S : Into < String > > ( & mut self , t : S , highlight : bool ) {
174
174
if highlight {
@@ -178,29 +178,31 @@ impl DiagnosticStyledString {
178
178
}
179
179
}
180
180
pub fn normal < S : Into < String > > ( t : S ) -> DiagnosticStyledString {
181
- DiagnosticStyledString ( vec ! [ StringPart :: Normal ( t. into( ) ) ] )
181
+ DiagnosticStyledString ( vec ! [ StringPart :: normal ( t. into( ) ) ] )
182
182
}
183
183
184
184
pub fn highlighted < S : Into < String > > ( t : S ) -> DiagnosticStyledString {
185
- DiagnosticStyledString ( vec ! [ StringPart :: Highlighted ( t. into( ) ) ] )
185
+ DiagnosticStyledString ( vec ! [ StringPart :: highlighted ( t. into( ) ) ] )
186
186
}
187
187
188
188
pub fn content ( & self ) -> String {
189
- self . 0 . iter ( ) . map ( |x| x. content ( ) ) . collect :: < String > ( )
189
+ self . 0 . iter ( ) . map ( |x| x. content . as_str ( ) ) . collect :: < String > ( )
190
190
}
191
191
}
192
192
193
193
#[ derive( Debug , PartialEq , Eq ) ]
194
- pub enum StringPart {
195
- Normal ( String ) ,
196
- Highlighted ( String ) ,
194
+ pub struct StringPart {
195
+ content : String ,
196
+ style : Style ,
197
197
}
198
198
199
199
impl StringPart {
200
- pub fn content ( & self ) -> & str {
201
- match self {
202
- & StringPart :: Normal ( ref s) | & StringPart :: Highlighted ( ref s) => s,
203
- }
200
+ fn normal ( content : String ) -> StringPart {
201
+ StringPart { content, style : Style :: NoStyle }
202
+ }
203
+
204
+ fn highlighted ( content : String ) -> StringPart {
205
+ StringPart { content, style : Style :: Highlight }
204
206
}
205
207
}
206
208
@@ -394,16 +396,10 @@ impl Diagnostic {
394
396
} ;
395
397
let mut msg: Vec < _ > =
396
398
vec ! [ ( format!( "{}{} `" , " " . repeat( expected_padding) , expected_label) , Style :: NoStyle ) ] ;
397
- msg. extend ( expected. 0 . iter ( ) . map ( |x| match * x {
398
- StringPart :: Normal ( ref s) => ( s. to_owned ( ) , Style :: NoStyle ) ,
399
- StringPart :: Highlighted ( ref s) => ( s. to_owned ( ) , Style :: Highlight ) ,
400
- } ) ) ;
399
+ msg. extend ( expected. 0 . into_iter ( ) . map ( |p| ( p. content , p. style ) ) ) ;
401
400
msg. push ( ( format ! ( "`{expected_extra}\n " ) , Style :: NoStyle ) ) ;
402
401
msg. push ( ( format ! ( "{}{} `" , " " . repeat( found_padding) , found_label) , Style :: NoStyle ) ) ;
403
- msg. extend ( found. 0 . iter ( ) . map ( |x| match * x {
404
- StringPart :: Normal ( ref s) => ( s. to_owned ( ) , Style :: NoStyle ) ,
405
- StringPart :: Highlighted ( ref s) => ( s. to_owned ( ) , Style :: Highlight ) ,
406
- } ) ) ;
402
+ msg. extend ( found. 0 . into_iter ( ) . map ( |p| ( p. content , p. style ) ) ) ;
407
403
msg. push ( ( format ! ( "`{found_extra}" ) , Style :: NoStyle ) ) ;
408
404
409
405
// For now, just attach these as notes.
0 commit comments