macro_rules! impl_consumer_factories {
() => {
#[allow(clippy::missing_errors_doc)]
#[must_use = "If not at least assigned to a variable, the return value will be dropped immediately, which in turn drops the internal tokio task, meaning that your callback is never called and the consumer effectively dies immediately. You can safely do a `let _consumer = ...` binding to ignore the typical 'unused' warning."]
pub fn inspect_chunks(
&self,
f: impl FnMut($crate::Chunk) -> $crate::Next + Send + 'static,
) -> FactoryReturn<$crate::Consumer<()>> {
self.consume_with(
$crate::output_stream::visitors::inspect::InspectChunks::builder()
.f(f)
.build(),
)
}
#[allow(clippy::missing_errors_doc)]
#[must_use = "If not at least assigned to a variable, the return value will be dropped immediately, which in turn drops the internal tokio task, meaning that your callback is never called and the consumer effectively dies immediately. You can safely do a `let _consumer = ...` binding to ignore the typical 'unused' warning."]
pub fn inspect_chunks_async<Fut>(
&self,
f: impl FnMut($crate::Chunk) -> Fut + Send + 'static,
) -> FactoryReturn<$crate::Consumer<()>>
where
Fut: ::std::future::Future<Output = $crate::Next> + Send + 'static,
{
self.consume_with_async(
$crate::output_stream::visitors::inspect::InspectChunksAsync::builder()
.f(f)
.build(),
)
}
#[allow(clippy::missing_errors_doc)]
#[must_use = "If not at least assigned to a variable, the return value will be dropped immediately, which in turn drops the internal tokio task, meaning that your callback is never called and the consumer effectively dies immediately. You can safely do a `let _consumer = ...` binding to ignore the typical 'unused' warning."]
pub fn inspect_lines(
&self,
f: impl FnMut(::std::borrow::Cow<'_, str>) -> $crate::Next + Send + 'static,
options: $crate::LineParsingOptions,
) -> FactoryReturn<$crate::Consumer<()>> {
self.consume_with($crate::output_stream::line::adapter::LineAdapter::new(
options,
$crate::output_stream::visitors::inspect::InspectLineSink::new(f),
))
}
#[allow(clippy::missing_errors_doc)]
#[must_use = "If not at least assigned to a variable, the return value will be dropped immediately, which in turn drops the internal tokio task, meaning that your callback is never called and the consumer effectively dies immediately. You can safely do a `let _consumer = ...` binding to ignore the typical 'unused' warning."]
pub fn inspect_lines_async<Fut>(
&self,
f: impl FnMut(::std::borrow::Cow<'_, str>) -> Fut + Send + 'static,
options: $crate::LineParsingOptions,
) -> FactoryReturn<$crate::Consumer<()>>
where
Fut: ::std::future::Future<Output = $crate::Next> + Send + 'static,
{
self.consume_with_async(
$crate::output_stream::line::adapter::LineAdapter::new(
options,
$crate::output_stream::visitors::inspect::InspectLineSinkAsync::new(f),
),
)
}
#[allow(clippy::missing_errors_doc)]
#[must_use = "If not at least assigned to a variable, the return value will be dropped immediately, which in turn drops the internal tokio task, meaning that your callback is never called and the consumer effectively dies immediately. You can safely do a `let _consumer = ...` binding to ignore the typical 'unused' warning."]
pub fn collect_chunks<S: $crate::Sink>(
&self,
into: S,
collect: impl FnMut($crate::Chunk, &mut S) + Send + 'static,
) -> FactoryReturn<$crate::Consumer<S>> {
self.consume_with(
$crate::output_stream::visitors::collect::CollectChunks::builder()
.sink(into)
.f(collect)
.build(),
)
}
#[allow(clippy::missing_errors_doc)]
#[must_use = "If not at least assigned to a variable, the return value will be dropped immediately, which in turn drops the internal tokio task, meaning that your callback is never called and the consumer effectively dies immediately. You can safely do a `let _consumer = ...` binding to ignore the typical 'unused' warning."]
pub fn collect_chunks_async<S, C>(
&self,
into: S,
collect: C,
) -> FactoryReturn<$crate::Consumer<S>>
where
S: $crate::Sink,
C: $crate::AsyncChunkCollector<S>,
{
self.consume_with_async(
$crate::output_stream::visitors::collect::CollectChunksAsync::builder()
.sink(into)
.collector(collect)
.build(),
)
}
#[allow(clippy::missing_errors_doc)]
#[must_use = "If not at least assigned to a variable, the return value will be dropped immediately, which in turn drops the internal tokio task, meaning that your callback is never called and the consumer effectively dies immediately. You can safely do a `let _consumer = ...` binding to ignore the typical 'unused' warning."]
pub fn collect_lines<S: $crate::Sink>(
&self,
into: S,
collect: impl FnMut(::std::borrow::Cow<'_, str>, &mut S) -> $crate::Next + Send + 'static,
options: $crate::LineParsingOptions,
) -> FactoryReturn<$crate::Consumer<S>> {
self.consume_with($crate::output_stream::line::adapter::LineAdapter::new(
options,
$crate::output_stream::visitors::collect::CollectLineSink::new(
into, collect,
),
))
}
#[allow(clippy::missing_errors_doc)]
#[must_use = "If not at least assigned to a variable, the return value will be dropped immediately, which in turn drops the internal tokio task, meaning that your callback is never called and the consumer effectively dies immediately. You can safely do a `let _consumer = ...` binding to ignore the typical 'unused' warning."]
pub fn collect_lines_async<S, C>(
&self,
into: S,
collect: C,
options: $crate::LineParsingOptions,
) -> FactoryReturn<$crate::Consumer<S>>
where
S: $crate::Sink,
C: $crate::AsyncLineCollector<S>,
{
self.consume_with_async(
$crate::output_stream::line::adapter::LineAdapter::new(
options,
$crate::output_stream::visitors::collect::CollectLineSinkAsync::new(
into, collect,
),
),
)
}
#[allow(clippy::missing_errors_doc)]
#[must_use = "If not at least assigned to a variable, the return value will be dropped immediately, which in turn drops the internal tokio task, meaning that your callback is never called and the consumer effectively dies immediately. You can safely do a `let _consumer = ...` binding to ignore the typical 'unused' warning."]
pub fn collect_chunks_into_vec(
&self,
options: $crate::RawCollectionOptions,
) -> FactoryReturn<$crate::Consumer<$crate::CollectedBytes>> {
self.consume_with(
$crate::output_stream::visitors::collect::CollectChunks::builder()
.sink($crate::CollectedBytes::new())
.f(move |chunk: $crate::Chunk, sink: &mut $crate::CollectedBytes| {
sink.push_chunk(chunk.as_ref(), options);
})
.build(),
)
}
#[allow(clippy::missing_errors_doc)]
#[must_use = "If not at least assigned to a variable, the return value will be dropped immediately, which in turn drops the internal tokio task, meaning that your callback is never called and the consumer effectively dies immediately. You can safely do a `let _consumer = ...` binding to ignore the typical 'unused' warning."]
pub fn collect_lines_into_vec(
&self,
parsing_options: $crate::LineParsingOptions,
collection_options: $crate::LineCollectionOptions,
) -> FactoryReturn<$crate::Consumer<$crate::CollectedLines>> {
self.consume_with($crate::output_stream::line::adapter::LineAdapter::new(
parsing_options,
$crate::output_stream::visitors::collect::CollectLineSink::new(
$crate::CollectedLines::new(),
move |line: ::std::borrow::Cow<'_, str>, sink: &mut $crate::CollectedLines| {
sink.push_line(line.into_owned(), collection_options);
$crate::Next::Continue
},
),
))
}
#[allow(clippy::missing_errors_doc)]
#[must_use = "If not at least assigned to a variable, the return value will be dropped immediately, which in turn drops the internal tokio task, meaning that your callback is never called and the consumer effectively dies immediately. You can safely do a `let _consumer = ...` binding to ignore the typical 'unused' warning."]
pub fn collect_chunks_into_write<W, H>(
&self,
write: W,
write_options: $crate::WriteCollectionOptions<H>,
) -> FactoryReturn<$crate::Consumer<::std::result::Result<W, $crate::SinkWriteError>>>
where
W: $crate::Sink + ::tokio::io::AsyncWriteExt + Unpin,
H: $crate::SinkWriteErrorHandler,
{
self.consume_with_async(
$crate::output_stream::visitors::write::WriteChunks::builder()
.stream_name($crate::output_stream::OutputStream::name(self))
.writer(write)
.error_handler(write_options.into_error_handler())
.mapper((|chunk: $crate::Chunk| chunk) as fn($crate::Chunk) -> $crate::Chunk)
.error(None)
.build(),
)
}
#[allow(clippy::missing_errors_doc)]
#[must_use = "If not at least assigned to a variable, the return value will be dropped immediately, which in turn drops the internal tokio task, meaning that your callback is never called and the consumer effectively dies immediately. You can safely do a `let _consumer = ...` binding to ignore the typical 'unused' warning."]
pub fn collect_lines_into_write<W, H>(
&self,
write: W,
options: $crate::LineParsingOptions,
mode: $crate::LineWriteMode,
write_options: $crate::WriteCollectionOptions<H>,
) -> FactoryReturn<$crate::Consumer<::std::result::Result<W, $crate::SinkWriteError>>>
where
W: $crate::Sink + ::tokio::io::AsyncWriteExt + Unpin,
H: $crate::SinkWriteErrorHandler,
{
self.consume_with_async(
$crate::output_stream::line::adapter::LineAdapter::new(
options,
$crate::output_stream::visitors::write::WriteLineSink::new(
$crate::output_stream::OutputStream::name(self),
write,
write_options.into_error_handler(),
(|line: ::std::borrow::Cow<'_, str>| line.into_owned())
as fn(::std::borrow::Cow<'_, str>) -> ::std::string::String,
mode,
),
),
)
}
#[allow(clippy::missing_errors_doc)]
#[must_use = "If not at least assigned to a variable, the return value will be dropped immediately, which in turn drops the internal tokio task, meaning that your callback is never called and the consumer effectively dies immediately. You can safely do a `let _consumer = ...` binding to ignore the typical 'unused' warning."]
pub fn collect_chunks_into_write_mapped<W, B, H>(
&self,
write: W,
mapper: impl Fn($crate::Chunk) -> B + Send + Sync + 'static,
write_options: $crate::WriteCollectionOptions<H>,
) -> FactoryReturn<$crate::Consumer<::std::result::Result<W, $crate::SinkWriteError>>>
where
W: $crate::Sink + ::tokio::io::AsyncWriteExt + Unpin,
B: AsRef<[u8]> + Send + 'static,
H: $crate::SinkWriteErrorHandler,
{
self.consume_with_async(
$crate::output_stream::visitors::write::WriteChunks::builder()
.stream_name($crate::output_stream::OutputStream::name(self))
.writer(write)
.error_handler(write_options.into_error_handler())
.mapper(mapper)
.error(None)
.build(),
)
}
#[allow(clippy::missing_errors_doc)]
#[must_use = "If not at least assigned to a variable, the return value will be dropped immediately, which in turn drops the internal tokio task, meaning that your callback is never called and the consumer effectively dies immediately. You can safely do a `let _consumer = ...` binding to ignore the typical 'unused' warning."]
pub fn collect_lines_into_write_mapped<W, B, H>(
&self,
write: W,
mapper: impl Fn(::std::borrow::Cow<'_, str>) -> B + Send + Sync + 'static,
options: $crate::LineParsingOptions,
mode: $crate::LineWriteMode,
write_options: $crate::WriteCollectionOptions<H>,
) -> FactoryReturn<$crate::Consumer<::std::result::Result<W, $crate::SinkWriteError>>>
where
W: $crate::Sink + ::tokio::io::AsyncWriteExt + Unpin,
B: AsRef<[u8]> + Send + 'static,
H: $crate::SinkWriteErrorHandler,
{
self.consume_with_async(
$crate::output_stream::line::adapter::LineAdapter::new(
options,
$crate::output_stream::visitors::write::WriteLineSink::new(
$crate::output_stream::OutputStream::name(self),
write,
write_options.into_error_handler(),
mapper,
mode,
),
),
)
}
};
}
pub(crate) use impl_consumer_factories;