pub struct WriteChunks<W, H, F, B>where
W: Sink + AsyncWriteExt + Unpin,
H: SinkWriteErrorHandler,
B: AsRef<[u8]> + Send + 'static,
F: Fn(Chunk) -> B + Send + Sync + 'static,{
pub stream_name: &'static str,
pub writer: W,
pub error_handler: H,
pub mapper: F,
pub error: Option<SinkWriteError>,
}Expand description
Asynchronous StreamVisitor that runs each observed chunk
through mapper, writes the resulting bytes via writer, and routes failures through
error_handler. The visitor surfaces the writer (or the first sink write error) via
AsyncStreamVisitor::into_output.
The two common shapes have dedicated constructors:
WriteChunks::passthroughwrites each chunk’s raw bytes unchanged.WriteChunks::mappedruns each chunk through a user mapper first.
If you need full control over every field (e.g. injecting a pre-existing
SinkWriteError into the error slot for tests), use
builder directly.
WriteChunks is AsyncStreamVisitor-only because the underlying writer is
AsyncWriteExt. There is no synchronous counterpart; reach for
CollectChunks (with a sink that performs the
blocking write) if you need a sync chunk-level visitor.
Fields§
§stream_name: &'static strStream name used to label any SinkWriteError this visitor surfaces.
writer: WAsync writer chunks are forwarded into.
error_handler: HRouting for sink write failures.
mapper: FPer-chunk mapper that produces the bytes actually written to writer.
error: Option<SinkWriteError>Latest sink write error, if any. Constructors initialize this to None.
The visitor writes into it before signaling Next::Break.
Implementations§
Source§impl<W, H, F, B> WriteChunks<W, H, F, B>
impl<W, H, F, B> WriteChunks<W, H, F, B>
Sourcepub fn builder() -> WriteChunksBuilder<W, H, F, B, ((), (), (), (), ())>
pub fn builder() -> WriteChunksBuilder<W, H, F, B, ((), (), (), (), ())>
Create a builder for building WriteChunks.
On the builder, call .stream_name(...), .writer(...), .error_handler(...), .mapper(...), .error(...)(optional) to set the values of the fields.
Finally, call .build() to create the instance of WriteChunks.
Source§impl<W, H> WriteChunks<W, H, fn(Chunk) -> Chunk, Chunk>
impl<W, H> WriteChunks<W, H, fn(Chunk) -> Chunk, Chunk>
Sourcepub fn passthrough(
stream_name: &'static str,
writer: W,
options: WriteCollectionOptions<H>,
) -> Self
pub fn passthrough( stream_name: &'static str, writer: W, options: WriteCollectionOptions<H>, ) -> Self
Identity-mapper constructor. Each chunk’s raw bytes are written to writer unchanged.
stream_name labels any SinkWriteError this visitor surfaces.
Source§impl<W, H, F, B> WriteChunks<W, H, F, B>
impl<W, H, F, B> WriteChunks<W, H, F, B>
Sourcepub fn mapped(
stream_name: &'static str,
writer: W,
options: WriteCollectionOptions<H>,
mapper: F,
) -> Self
pub fn mapped( stream_name: &'static str, writer: W, options: WriteCollectionOptions<H>, mapper: F, ) -> Self
Mapped constructor. Each chunk is run through mapper before being written. Use this
when the bytes you want to forward differ from the raw chunk bytes (for example, a
rendered line, an envelope-wrapped frame, or a transcoded representation).
Trait Implementations§
Source§impl<W, H, F, B> AsyncStreamVisitor for WriteChunks<W, H, F, B>
impl<W, H, F, B> AsyncStreamVisitor for WriteChunks<W, H, F, B>
Source§type Output = Result<W, SinkWriteError>
type Output = Result<W, SinkWriteError>
into_output after the visitor
has finished observing the stream. Returned via Consumer::wait
and Consumer::cancel.