Skip to main content

WriteChunks

Struct WriteChunks 

Source
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:

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 str

Stream name used to label any SinkWriteError this visitor surfaces.

§writer: W

Async writer chunks are forwarded into.

§error_handler: H

Routing for sink write failures.

§mapper: F

Per-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>
where W: Sink + AsyncWriteExt + Unpin, H: SinkWriteErrorHandler, B: AsRef<[u8]> + Send + 'static, F: Fn(Chunk) -> B + Send + Sync + 'static,

Source

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>

Source

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>
where W: Sink + AsyncWriteExt + Unpin, H: SinkWriteErrorHandler, B: AsRef<[u8]> + Send + 'static, F: Fn(Chunk) -> B + Send + Sync + 'static,

Source

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>
where W: Sink + AsyncWriteExt + Unpin, H: SinkWriteErrorHandler, B: AsRef<[u8]> + Send + 'static, F: Fn(Chunk) -> B + Send + Sync + 'static,

Source§

type Output = Result<W, SinkWriteError>

The value produced by into_output after the visitor has finished observing the stream. Returned via Consumer::wait and Consumer::cancel.
Source§

async fn on_chunk(&mut self, chunk: Chunk) -> Next

Asynchronously observes a single chunk. Read more
Source§

fn into_output(self) -> Self::Output

Consumes the visitor and returns its final output. Read more
Source§

fn on_gap(&mut self)

Invoked when the stream backend reports that one or more chunks were dropped between the last delivered chunk and the next one. Read more
Source§

fn on_eof(&mut self) -> impl Future<Output = ()> + Send + '_

Asynchronously observes end-of-stream. Read more

Auto Trait Implementations§

§

impl<W, H, F, B> Freeze for WriteChunks<W, H, F, B>
where W: Freeze, H: Freeze, F: Freeze,

§

impl<W, H, F, B> !RefUnwindSafe for WriteChunks<W, H, F, B>

§

impl<W, H, F, B> Send for WriteChunks<W, H, F, B>

§

impl<W, H, F, B> Sync for WriteChunks<W, H, F, B>
where W: Sync, H: Sync,

§

impl<W, H, F, B> Unpin for WriteChunks<W, H, F, B>
where H: Unpin, F: Unpin,

§

impl<W, H, F, B> UnsafeUnpin for WriteChunks<W, H, F, B>

§

impl<W, H, F, B> !UnwindSafe for WriteChunks<W, H, F, B>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Sink for T
where T: Send + 'static,