rust - Splitting a futures::Stream into multiple streams based on a property of the stream item -


i have stream of items (u32, bytes) integer index in range 0..n split stream n streams, filtering integer.

i considered several possibilities, including

  • creating n streams each of peeks @ underlying stream determine if next item it
  • pushing items 1 of n sinks when arrive, , use other side of sink stream again. (this seems related forwarding futures::stream futures::sink.).

i feel neither of these possibilities convincing. first 1 seems create unnecessary overhead , second 1 not elegant (if works, not sure).

what's way of splitting stream?

at 1 point had similar requirement , wrote group_by operator stream.

i haven't yet published crates.io didn't feel ready consumption feel free take @ code @ https://github.com/lukazoid/lz_stream_tools or attempt use yourself.

add following cargo.toml:

[dependencies] lz_stream_tools = { git = "https://github.com/lukazoid/lz_stream_tools" } 

and extern crate lz_stream_tools; bin.rs/lib.rs.

then code may use so:

use lz_stream_tools::streamtools;  let groups = some_stream.group_by(|x| x.0); 

groups stream of (u32, stream<item=bytes)).


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -