1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*******************************************************************************
*
* Copyright (c) 2026.
* Haixing Hu, Qubit Co. Ltd.
*
* All rights reserved.
*
******************************************************************************/
#[cfg(coverage)]
use std::io::Write;
use std::{
fs::File,
path::PathBuf,
};
use super::output_tee::OutputTee;
/// Output capture options moved into a reader thread.
pub(crate) struct OutputCaptureOptions {
/// Maximum bytes retained in memory.
pub(crate) max_bytes: Option<usize>,
/// Optional writer receiving a streaming copy.
pub(crate) tee: Option<OutputTee>,
}
impl OutputCaptureOptions {
/// Creates output capture options.
///
/// # Parameters
///
/// * `max_bytes` - Optional in-memory retention limit.
/// * `file` - Optional file receiving all emitted bytes.
/// * `file_path` - File path used in write-failure diagnostics.
///
/// # Returns
///
/// Capture options moved into the output reader thread.
pub(crate) fn new(
max_bytes: Option<usize>,
file: Option<File>,
file_path: Option<PathBuf>,
) -> Self {
let tee = file.map(|file| OutputTee {
writer: Box::new(file),
path: file_path.unwrap_or_default(),
});
Self { max_bytes, tee }
}
/// Creates output capture options from an arbitrary writer.
///
/// # Parameters
///
/// * `max_bytes` - Optional in-memory retention limit.
/// * `writer` - Writer receiving all emitted bytes.
/// * `path` - Diagnostic path reported when writes fail.
///
/// # Returns
///
/// Capture options moved into the output reader thread.
#[cfg(coverage)]
pub(crate) fn new_writer(
max_bytes: Option<usize>,
writer: Box<dyn Write + Send>,
path: PathBuf,
) -> Self {
Self {
max_bytes,
tee: Some(OutputTee { writer, path }),
}
}
}