@@ -168,12 +168,17 @@ enum CaptureKind {
168
168
/// Use the old output-capture implementation, which relies on the unstable
169
169
/// library feature `#![feature(internal_output_capture)]`.
170
170
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 } ,
171
174
}
172
175
173
176
impl CaptureKind {
174
177
fn for_config ( config : & Config ) -> Self {
175
178
if config. nocapture {
176
179
Self :: None
180
+ } else if config. new_output_capture {
181
+ Self :: New { buf : output_capture:: CaptureBuf :: new ( ) }
177
182
} else {
178
183
// Create a capure buffer for `io::set_output_capture`.
179
184
Self :: Old { buf : Default :: default ( ) }
@@ -184,21 +189,30 @@ impl CaptureKind {
184
189
match self {
185
190
Self :: None => false ,
186
191
Self :: Old { .. } => true ,
192
+ Self :: New { .. } => true ,
187
193
}
188
194
}
189
195
190
196
fn stdout ( & self ) -> & dyn ConsoleOut {
191
- & output_capture:: Stdout
197
+ self . capture_buf_or ( & output_capture:: Stdout )
192
198
}
193
199
194
200
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
+ }
196
209
}
197
210
198
211
fn into_inner ( self ) -> Option < Vec < u8 > > {
199
212
match self {
200
213
Self :: None => None ,
201
214
Self :: Old { buf } => Some ( buf. lock ( ) . unwrap_or_else ( |e| e. into_inner ( ) ) . to_vec ( ) ) ,
215
+ Self :: New { buf } => Some ( buf. into_inner ( ) . into ( ) ) ,
202
216
}
203
217
}
204
218
}
0 commit comments