@@ -168,12 +168,17 @@ enum CaptureKind {
168168 /// Use the old output-capture implementation, which relies on the unstable
169169 /// library feature `#![feature(internal_output_capture)]`.
170170 Old { buf : Arc < Mutex < Vec < u8 > > > } ,
171+
172+ /// Use the new output-capture implementation, which only uses stable Rust.
173+ New { buf : output_capture:: CaptureBuf } ,
171174}
172175
173176impl CaptureKind {
174177 fn for_config ( config : & Config ) -> Self {
175178 if config. nocapture {
176179 Self :: None
180+ } else if config. new_output_capture {
181+ Self :: New { buf : output_capture:: CaptureBuf :: new ( ) }
177182 } else {
178183 // Create a capure buffer for `io::set_output_capture`.
179184 Self :: Old { buf : Default :: default ( ) }
@@ -184,21 +189,30 @@ impl CaptureKind {
184189 match self {
185190 Self :: None => false ,
186191 Self :: Old { .. } => true ,
192+ Self :: New { .. } => true ,
187193 }
188194 }
189195
190196 fn stdout ( & self ) -> & dyn ConsoleOut {
191- & output_capture:: Stdout
197+ self . capture_buf_or ( & output_capture:: Stdout )
192198 }
193199
194200 fn stderr ( & self ) -> & dyn ConsoleOut {
195- & output_capture:: Stderr
201+ self . capture_buf_or ( & output_capture:: Stderr )
202+ }
203+
204+ fn capture_buf_or < ' a > ( & ' a self , fallback : & ' a dyn ConsoleOut ) -> & ' a dyn ConsoleOut {
205+ match self {
206+ Self :: None | Self :: Old { .. } => fallback,
207+ Self :: New { buf } => buf,
208+ }
196209 }
197210
198211 fn into_inner ( self ) -> Option < Vec < u8 > > {
199212 match self {
200213 Self :: None => None ,
201214 Self :: Old { buf } => Some ( buf. lock ( ) . unwrap_or_else ( |e| e. into_inner ( ) ) . to_vec ( ) ) ,
215+ Self :: New { buf } => Some ( buf. into_inner ( ) . into ( ) ) ,
202216 }
203217 }
204218}
0 commit comments