Skip to main content

tokio_process_tools/output_stream/backend/discard/
mod.rs

1//! Discard backend: a zero-cost stream marker for stdio configured as `Stdio::null()`.
2//!
3//! A [`DiscardedOutputStream`] holds no buffers and spawns no reader task. The OS routes the child's
4//! stdout or stderr to `/dev/null` (or its platform equivalent), and the parent never sees the
5//! bytes. Because there is nothing to subscribe to, the type intentionally does not implement
6//! [`crate::TrySubscribable`], so consumer-attaching APIs (`wait_for_completion_with_output`,
7//! `inspect_lines`, etc.) are not in scope on a process whose stream is discarded.
8
9use crate::output_stream::OutputStream;
10use crate::output_stream::num_bytes::NumBytes;
11
12/// Marker stream for a stdio slot configured with [`std::process::Stdio::null()`].
13///
14/// The OS discards the child's writes; no pipe is allocated and no reader task runs. The
15/// `read_chunk_size` and `max_buffered_chunks` accessors are present because [`OutputStream`]
16/// requires them, but they have no operational meaning for this variant and return zero.
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub struct DiscardedOutputStream {
19    name: &'static str,
20}
21
22impl DiscardedOutputStream {
23    pub(crate) fn new(name: &'static str) -> Self {
24        Self { name }
25    }
26}
27
28impl OutputStream for DiscardedOutputStream {
29    fn read_chunk_size(&self) -> NumBytes {
30        NumBytes::zero()
31    }
32
33    fn max_buffered_chunks(&self) -> usize {
34        0
35    }
36
37    fn name(&self) -> &'static str {
38        self.name
39    }
40}