@@ -45,12 +45,13 @@ pub trait Source: Send {
4545/// Something that can write the contents of a buffer somewhere
4646///
4747/// For example, this is implemented for a file writer.
48- pub trait Sink : Send {
48+ pub trait Sink : Send + Sized {
4949 /// Write all data from the buffer to the sink
5050 fn sink ( & mut self , buffer : & [ u8 ] ) -> Result < ( ) , io:: Error > ;
5151
52- /// Complete and flush any remaining data from the sink
53- fn flush ( self ) -> Result < ( ) , io:: Error > ;
52+ /// Complete and flush any remaining data from the sink, returning it
53+ /// so the caller can perform additional finalization (e.g. async S3 upload).
54+ fn flush ( self ) -> Result < Self , io:: Error > ;
5455}
5556
5657/// Generates data in parallel from a series of [`Source`] and writes to a [`Sink`]
@@ -69,7 +70,7 @@ pub async fn generate_in_chunks<G, I, S>(
6970 mut sink : S ,
7071 sources : I ,
7172 num_threads : usize ,
72- ) -> Result < ( ) , io:: Error >
73+ ) -> Result < S , io:: Error >
7374where
7475 G : Source + ' static ,
7576 I : Iterator < Item = G > ,
8687
8788 // write the header
8889 let Some ( first) = sources. peek ( ) else {
89- return Ok ( ( ) ) ; // no sources
90+ return Ok ( sink ) ; // no sources
9091 } ;
9192 let header = first. header ( Vec :: new ( ) ) ;
9293 tx. send ( header)
@@ -131,7 +132,8 @@ where
131132 sink. sink ( & buffer) ?;
132133 captured_recycler. return_buffer ( buffer) ;
133134 }
134- // No more input, flush the sink and return
135+ // No more input, flush the sink and return it so the caller can
136+ // perform additional finalization (e.g. async S3 upload).
135137 sink. flush ( )
136138 } ) ;
137139
0 commit comments