Wrap sink by a function which may produce multiple items into a sink on a single call

I have discovered with extension method for a sink: https://docs.rs/futures/0.3.7/futures/sink/trait.SinkExt.html#method.with
I understand it creates a sink which calls the provided callback function with an input item value and submits output result of the callback function to the wrapped sink.
I have got a situation where a callback function may result zero or multiple (ie. a stream or an array) items to be forwarded to the wrapped sink. What would be the recommended way to implement such a sink? It is a real puzzle for me so far....

with_flat_map is what you’re looking for, I think: the function you provide needs to return a Stream, and each item from that stream is fed to the wrapped Sink in turn.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.