pub struct SingleSubscriberOutputStream<D = BestEffortDelivery, R = NoReplay>{ /* private fields */ }Expand description
The output stream from a process. Either representing stdout or stderr.
This is the single-subscriber variant, allowing exactly one active consumer at a time. It is
useful when one inspector, collector, or line waiter should own the stream and accidental
concurrent fanout should be rejected early. It can reduce coordination overhead in some
single-consumer paths, but it is not a categorical throughput replacement for broadcast.
If multiple concurrent consumers are required, use the
output_stream::backend::broadcast::BroadcastOutputStream.
Implementations§
Source§impl<D, R> SingleSubscriberOutputStream<D, R>
impl<D, R> SingleSubscriberOutputStream<D, R>
Sourcepub fn from_stream<S>(
stream: S,
stream_name: &'static str,
options: StreamConfig<D, R>,
) -> Self
pub fn from_stream<S>( stream: S, stream_name: &'static str, options: StreamConfig<D, R>, ) -> Self
Creates a new single-subscriber output stream from an async read stream and typed stream config.
Sourcepub fn replay_enabled(&self) -> bool
pub fn replay_enabled(&self) -> bool
Returns whether replay-specific APIs are enabled for this stream.
Sourcepub fn replay_retention(&self) -> Option<ReplayRetention>
pub fn replay_retention(&self) -> Option<ReplayRetention>
Returns the configured replay retention.
Source§impl<D> SingleSubscriberOutputStream<D, ReplayEnabled>where
D: Delivery,
impl<D> SingleSubscriberOutputStream<D, ReplayEnabled>where
D: Delivery,
Sourcepub fn seal_replay(&self)
pub fn seal_replay(&self)
Seals replay history for future subscribers.
This is a one-way, idempotent operation.
§Panics
Panics if the internal state mutex is poisoned.
Sourcepub fn is_replay_sealed(&self) -> bool
pub fn is_replay_sealed(&self) -> bool
Returns true once replay history has been sealed.
§Panics
Panics if the internal state mutex is poisoned.
Source§impl<D, R> SingleSubscriberOutputStream<D, R>
impl<D, R> SingleSubscriberOutputStream<D, R>
Sourcepub fn consume_with<V>(
&self,
visitor: V,
) -> Result<Consumer<V::Output>, StreamConsumerError>where
V: StreamVisitor,
pub fn consume_with<V>(
&self,
visitor: V,
) -> Result<Consumer<V::Output>, StreamConsumerError>where
V: StreamVisitor,
Tries to drive the provided synchronous StreamVisitor over this stream.
Returns a Consumer that owns the spawned task driving the visitor. All built-in
inspect_*, collect_*, and wait_for_line factories construct a built-in visitor and
call this method internally.
§Errors
Returns StreamConsumerError if the backend rejects the consumer (single-subscriber
streams allow only one active consumer or line waiter at a time).
Sourcepub fn consume_with_async<V>(
&self,
visitor: V,
) -> Result<Consumer<V::Output>, StreamConsumerError>where
V: AsyncStreamVisitor,
pub fn consume_with_async<V>(
&self,
visitor: V,
) -> Result<Consumer<V::Output>, StreamConsumerError>where
V: AsyncStreamVisitor,
Tries to drive the provided asynchronous AsyncStreamVisitor over this stream.
§Errors
Returns StreamConsumerError if the backend rejects the consumer.
Sourcepub fn inspect_chunks(
&self,
f: impl FnMut(Chunk) -> Next + Send + 'static,
) -> Result<Consumer<()>, StreamConsumerError>
pub fn inspect_chunks( &self, f: impl FnMut(Chunk) -> Next + Send + 'static, ) -> Result<Consumer<()>, StreamConsumerError>
Inspects chunks of output from the stream without storing them.
The provided closure is called for each chunk of data. Return Next::Continue to
keep processing or Next::Break to stop.
Sourcepub fn inspect_chunks_async<Fut>(
&self,
f: impl FnMut(Chunk) -> Fut + Send + 'static,
) -> Result<Consumer<()>, StreamConsumerError>
pub fn inspect_chunks_async<Fut>( &self, f: impl FnMut(Chunk) -> Fut + Send + 'static, ) -> Result<Consumer<()>, StreamConsumerError>
Inspects chunks of output from the stream without storing them, using an async closure.
The provided async closure is called for each chunk of data. Return
Next::Continue to keep processing or Next::Break to stop.
Sourcepub fn inspect_lines(
&self,
f: impl FnMut(Cow<'_, str>) -> Next + Send + 'static,
options: LineParsingOptions,
) -> Result<Consumer<()>, StreamConsumerError>
pub fn inspect_lines( &self, f: impl FnMut(Cow<'_, str>) -> Next + Send + 'static, options: LineParsingOptions, ) -> Result<Consumer<()>, StreamConsumerError>
Inspects lines of output from the stream without storing them.
The provided closure is called for each line. Return Next::Continue to keep
processing or Next::Break to stop.
§Panics
Panics if options.max_line_length is zero.
Sourcepub fn inspect_lines_async<Fut>(
&self,
f: impl FnMut(Cow<'_, str>) -> Fut + Send + 'static,
options: LineParsingOptions,
) -> Result<Consumer<()>, StreamConsumerError>
pub fn inspect_lines_async<Fut>( &self, f: impl FnMut(Cow<'_, str>) -> Fut + Send + 'static, options: LineParsingOptions, ) -> Result<Consumer<()>, StreamConsumerError>
Inspects lines of output from the stream without storing them, using an async closure.
The provided async closure is called for each line. Return Next::Continue to
keep processing or Next::Break to stop.
§Panics
Panics if options.max_line_length is zero.
Sourcepub fn collect_chunks<S: Sink>(
&self,
into: S,
collect: impl FnMut(Chunk, &mut S) + Send + 'static,
) -> Result<Consumer<S>, StreamConsumerError>
pub fn collect_chunks<S: Sink>( &self, into: S, collect: impl FnMut(Chunk, &mut S) + Send + 'static, ) -> Result<Consumer<S>, StreamConsumerError>
Collects chunks from the stream into a sink.
The provided closure is called for each chunk, with mutable access to the sink.
Sourcepub fn collect_chunks_async<S, C>(
&self,
into: S,
collect: C,
) -> Result<Consumer<S>, StreamConsumerError>where
S: Sink,
C: AsyncChunkCollector<S>,
pub fn collect_chunks_async<S, C>(
&self,
into: S,
collect: C,
) -> Result<Consumer<S>, StreamConsumerError>where
S: Sink,
C: AsyncChunkCollector<S>,
Collects chunks from the stream into a sink using an async collector.
The provided async collector is called for each chunk, with mutable access to the sink.
Sourcepub fn collect_lines<S: Sink>(
&self,
into: S,
collect: impl FnMut(Cow<'_, str>, &mut S) -> Next + Send + 'static,
options: LineParsingOptions,
) -> Result<Consumer<S>, StreamConsumerError>
pub fn collect_lines<S: Sink>( &self, into: S, collect: impl FnMut(Cow<'_, str>, &mut S) -> Next + Send + 'static, options: LineParsingOptions, ) -> Result<Consumer<S>, StreamConsumerError>
Collects lines from the stream into a sink.
The provided closure is called for each line, with mutable access to the sink.
Return Next::Continue to keep processing or Next::Break to stop.
§Panics
Panics if options.max_line_length is zero.
Sourcepub fn collect_lines_async<S, C>(
&self,
into: S,
collect: C,
options: LineParsingOptions,
) -> Result<Consumer<S>, StreamConsumerError>where
S: Sink,
C: AsyncLineCollector<S>,
pub fn collect_lines_async<S, C>(
&self,
into: S,
collect: C,
options: LineParsingOptions,
) -> Result<Consumer<S>, StreamConsumerError>where
S: Sink,
C: AsyncLineCollector<S>,
Collects lines from the stream into a sink using an async collector.
The provided async collector is called for each line, with mutable access to the
sink. Return Next::Continue to keep processing or Next::Break to stop.
§Panics
Panics if options.max_line_length is zero.
Sourcepub fn collect_chunks_into_vec(
&self,
options: RawCollectionOptions,
) -> Result<Consumer<CollectedBytes>, StreamConsumerError>
pub fn collect_chunks_into_vec( &self, options: RawCollectionOptions, ) -> Result<Consumer<CollectedBytes>, StreamConsumerError>
Convenience method to collect chunks into a bounded byte vector.
Sourcepub fn collect_lines_into_vec(
&self,
parsing_options: LineParsingOptions,
collection_options: LineCollectionOptions,
) -> Result<Consumer<CollectedLines>, StreamConsumerError>
pub fn collect_lines_into_vec( &self, parsing_options: LineParsingOptions, collection_options: LineCollectionOptions, ) -> Result<Consumer<CollectedLines>, StreamConsumerError>
Convenience method to collect lines into a line buffer.
parsing_options.max_line_length must be non-zero unless collection_options is
LineCollectionOptions::TrustedUnbounded.
§Panics
Panics if parsing_options.max_line_length is zero and bounded collection is used.
Sourcepub fn collect_chunks_into_write<W, H>(
&self,
write: W,
write_options: WriteCollectionOptions<H>,
) -> Result<Consumer<Result<W, SinkWriteError>>, StreamConsumerError>
pub fn collect_chunks_into_write<W, H>( &self, write: W, write_options: WriteCollectionOptions<H>, ) -> Result<Consumer<Result<W, SinkWriteError>>, StreamConsumerError>
Collects chunks into an async writer.
Sink write failures are handled according to write_options. Use
WriteCollectionOptions::fail_fast to stop collection and surface the
SinkWriteError as the inner Err of the resulting Result<W, SinkWriteError>,
WriteCollectionOptions::log_and_continue to log each failure and keep
collecting, or WriteCollectionOptions::with_error_handler to make a per-error
continue-or-stop decision.
Sourcepub fn collect_lines_into_write<W, H>(
&self,
write: W,
options: LineParsingOptions,
mode: LineWriteMode,
write_options: WriteCollectionOptions<H>,
) -> Result<Consumer<Result<W, SinkWriteError>>, StreamConsumerError>
pub fn collect_lines_into_write<W, H>( &self, write: W, options: LineParsingOptions, mode: LineWriteMode, write_options: WriteCollectionOptions<H>, ) -> Result<Consumer<Result<W, SinkWriteError>>, StreamConsumerError>
Collects lines into an async writer.
Parsed lines no longer include their trailing newline byte, so mode controls
whether a \n delimiter should be reintroduced for each emitted line.
Sink write failures are handled according to write_options — see
collect_chunks_into_write for the
failure-handling options.
Sourcepub fn collect_chunks_into_write_mapped<W, B, H>(
&self,
write: W,
mapper: impl Fn(Chunk) -> B + Send + Sync + 'static,
write_options: WriteCollectionOptions<H>,
) -> Result<Consumer<Result<W, SinkWriteError>>, StreamConsumerError>
pub fn collect_chunks_into_write_mapped<W, B, H>( &self, write: W, mapper: impl Fn(Chunk) -> B + Send + Sync + 'static, write_options: WriteCollectionOptions<H>, ) -> Result<Consumer<Result<W, SinkWriteError>>, StreamConsumerError>
Collects chunks into an async writer after mapping them with the provided function.
Sink write failures are handled according to write_options — see
collect_chunks_into_write for the
failure-handling options.
Sourcepub fn collect_lines_into_write_mapped<W, B, H>(
&self,
write: W,
mapper: impl Fn(Cow<'_, str>) -> B + Send + Sync + 'static,
options: LineParsingOptions,
mode: LineWriteMode,
write_options: WriteCollectionOptions<H>,
) -> Result<Consumer<Result<W, SinkWriteError>>, StreamConsumerError>
pub fn collect_lines_into_write_mapped<W, B, H>( &self, write: W, mapper: impl Fn(Cow<'_, str>) -> B + Send + Sync + 'static, options: LineParsingOptions, mode: LineWriteMode, write_options: WriteCollectionOptions<H>, ) -> Result<Consumer<Result<W, SinkWriteError>>, StreamConsumerError>
Collects lines into an async writer after mapping them with the provided function.
mode applies after mapper: choose LineWriteMode::AsIs when the mapped
output already contains delimiters, or LineWriteMode::AppendLf to append \n
after each mapped line.
Sink write failures are handled according to write_options — see
collect_chunks_into_write for the
failure-handling options.
Sourcepub fn wait_for_line(
&self,
timeout: Duration,
predicate: impl Fn(Cow<'_, str>) -> bool + Send + Sync + 'static,
options: LineParsingOptions,
) -> Result<impl Future<Output = Result<WaitForLineResult, StreamReadError>> + Send + 'static, StreamConsumerError>
pub fn wait_for_line( &self, timeout: Duration, predicate: impl Fn(Cow<'_, str>) -> bool + Send + Sync + 'static, options: LineParsingOptions, ) -> Result<impl Future<Output = Result<WaitForLineResult, StreamReadError>> + Send + 'static, StreamConsumerError>
Tries to wait for a line that matches the given predicate within timeout.
§Errors
Returns StreamConsumerError if the backend rejects the line waiter.
§Panics
Panics if options.max_line_length is zero.
Trait Implementations§
Source§impl<D, R> Debug for SingleSubscriberOutputStream<D, R>
impl<D, R> Debug for SingleSubscriberOutputStream<D, R>
Source§impl<D, R> Drop for SingleSubscriberOutputStream<D, R>
impl<D, R> Drop for SingleSubscriberOutputStream<D, R>
Source§impl<D, R> OutputStream for SingleSubscriberOutputStream<D, R>
impl<D, R> OutputStream for SingleSubscriberOutputStream<D, R>
Source§fn read_chunk_size(&self) -> NumBytes
fn read_chunk_size(&self) -> NumBytes
stream_reader.