]> git.lizzy.rs Git - rust.git/blob - src/libtest/helpers/sink.rs
Rollup merge of #68176 - GuillaumeGomez:clean-up-err-codes, r=Dylan-DPC
[rust.git] / src / libtest / helpers / sink.rs
1 //! Module providing a helper structure to capture output in subprocesses.
2
3 use std::{
4     io,
5     io::prelude::Write,
6     sync::{Arc, Mutex},
7 };
8
9 pub struct Sink(Arc<Mutex<Vec<u8>>>);
10
11 impl Sink {
12     pub fn new_boxed(data: &Arc<Mutex<Vec<u8>>>) -> Box<Self> {
13         Box::new(Self(data.clone()))
14     }
15 }
16
17 impl Write for Sink {
18     fn write(&mut self, data: &[u8]) -> io::Result<usize> {
19         Write::write(&mut *self.0.lock().unwrap(), data)
20     }
21     fn flush(&mut self) -> io::Result<()> {
22         Ok(())
23     }
24 }