I'm looking to write an iterator Item = u8 to a file. The iterator has a large len so collecting the iterator and then writing the resulting vector isn't very efficient.
I'm thinking of collecting chunks of the iterator and writing chunk by chunk but that also doesn't seem particularly efficient, is there a better/more efficient way to do it (Ideally something which allows me to pipe the iterator strait into a Bufwriter or similar)?
Thanks
BufWriterand write a single byte at a time.BufWriterwill take care of the buffering.u8's i.e.&[u8]rather than a singleu8and I'm assuming that there would be a performance overhead from converting each byte into a slice i.e.buf_writer.write(&[byte])BufWriter; but that kind of pooling is exactly whatBufWriteralready does, and does so as efficient as it gets. Long story short, as @AleksanderKrauze said: Either write single-byte slices into aBufWriter, or redesign the source. Avoid the temptation to copy buffers from buffers into other buffers.writefor each byte is going to be way more costly than converting a byte into a byte slice.