406: return document count from builder r=MarinPostma a=MarinPostma

`DocumentBatchBuilder::finish` now returns the number of documents in the batch. This is more compact that calling `len()` just before calling finish.


Co-authored-by: marin postma <postma.marin@protonmail.com>
This commit is contained in:
bors[bot] 2021-10-28 08:42:38 +00:00 committed by GitHub
commit 9875f2646a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -62,7 +62,7 @@ impl<W: io::Write + io::Seek> DocumentBatchBuilder<W> {
/// This method must be called after the document addition is terminated. It will put the
/// metadata at the end of the file, and write the metadata offset at the beginning on the
/// file.
pub fn finish(self) -> Result<(), Error> {
pub fn finish(self) -> Result<usize, Error> {
let Self { inner: ByteCounter { mut writer, count: offset }, index, count, .. } = self;
let meta = DocumentsMetadata { count, index };
@ -74,7 +74,7 @@ impl<W: io::Write + io::Seek> DocumentBatchBuilder<W> {
writer.flush()?;
Ok(())
Ok(count)
}
/// Extends the builder with json documents from a reader.