1- use std:: { io , io :: prelude :: Write } ;
1+ use std:: io ;
22
33use super :: OutputFormatter ;
44use crate :: {
55 bench:: fmt_bench_samples,
6- console:: { ConsoleTestDiscoveryState , ConsoleTestState , OutputLocation } ,
6+ console:: { ConsoleTestDiscoveryState , ConsoleTestState , Output } ,
77 term,
88 test_result:: TestResult ,
99 time,
@@ -15,8 +15,8 @@ use crate::{
1515// result chars leaves 12 chars for a progress count like " 11704/12853".
1616const QUIET_MODE_MAX_COLUMN : usize = 88 ;
1717
18- pub ( crate ) struct TerseFormatter < T > {
19- out : OutputLocation < T > ,
18+ pub ( crate ) struct TerseFormatter < ' a > {
19+ out : & ' a mut dyn Output ,
2020 use_color : bool ,
2121 is_multithreaded : bool ,
2222 /// Number of columns to fill when aligning names
@@ -27,9 +27,9 @@ pub(crate) struct TerseFormatter<T> {
2727 total_test_count : usize ,
2828}
2929
30- impl < T : Write > TerseFormatter < T > {
30+ impl < ' a > TerseFormatter < ' a > {
3131 pub fn new (
32- out : OutputLocation < T > ,
32+ out : & ' a mut dyn Output ,
3333 use_color : bool ,
3434 max_name_len : usize ,
3535 is_multithreaded : bool ,
@@ -98,29 +98,13 @@ impl<T: Write> TerseFormatter<T> {
9898 Ok ( ( ) )
9999 }
100100
101- pub fn write_pretty ( & mut self , word : & str , color : term:: color:: Color ) -> io:: Result < ( ) > {
102- match self . out {
103- OutputLocation :: Pretty ( ref mut term) => {
104- if self . use_color {
105- term. fg ( color) ?;
106- }
107- term. write_all ( word. as_bytes ( ) ) ?;
108- if self . use_color {
109- term. reset ( ) ?;
110- }
111- term. flush ( )
112- }
113- OutputLocation :: Raw ( ref mut stdout) => {
114- stdout. write_all ( word. as_bytes ( ) ) ?;
115- stdout. flush ( )
116- }
117- }
101+ fn write_pretty ( & mut self , word : & str , color : term:: color:: Color ) -> io:: Result < ( ) > {
102+ if self . use_color { self . out . write_pretty ( word, color) } else { self . out . write_plain ( word) }
118103 }
119104
120- pub fn write_plain < S : AsRef < str > > ( & mut self , s : S ) -> io:: Result < ( ) > {
105+ fn write_plain < S : AsRef < str > > ( & mut self , s : S ) -> io:: Result < ( ) > {
121106 let s = s. as_ref ( ) ;
122- self . out . write_all ( s. as_bytes ( ) ) ?;
123- self . out . flush ( )
107+ self . out . write_plain ( s)
124108 }
125109
126110 pub fn write_outputs ( & mut self , state : & ConsoleTestState ) -> io:: Result < ( ) > {
@@ -187,7 +171,7 @@ impl<T: Write> TerseFormatter<T> {
187171 }
188172}
189173
190- impl < T : Write > OutputFormatter for TerseFormatter < T > {
174+ impl OutputFormatter for TerseFormatter < ' _ > {
191175 fn write_discovery_start ( & mut self ) -> io:: Result < ( ) > {
192176 Ok ( ( ) )
193177 }
0 commit comments