From 3fcccc31b5885029499056adaaf42853ab45d1ce Mon Sep 17 00:00:00 2001 From: marin postma Date: Mon, 25 Oct 2021 10:26:28 +0200 Subject: [PATCH] add document builder example --- milli/src/documents/builder.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/milli/src/documents/builder.rs b/milli/src/documents/builder.rs index d54d9639c..144dcdfa9 100644 --- a/milli/src/documents/builder.rs +++ b/milli/src/documents/builder.rs @@ -16,7 +16,20 @@ use super::{ByteCounter, DocumentsBatchIndex, DocumentsMetadata, Error}; /// format used by milli. /// /// The writer used by the DocumentBatchBuilder can be read using a `DocumentBatchReader` to -/// iterate other the documents. +/// iterate over the documents. +/// +/// ## example: +/// ``` +/// use milli::documents::DocumentBatchBuilder; +/// use serde_json::json; +/// use std::io::Cursor; +/// +/// let json = r##"{"id": 1, "name": "foo"}"##; +/// let mut writer = Cursor::new(Vec::new()); +/// let mut builder = DocumentBatchBuilder::new(&mut writer).unwrap(); +/// builder.extend_from_json(Cursor::new(json.as_bytes())).unwrap(); +/// builder.finish().unwrap(); +/// ``` pub struct DocumentBatchBuilder { inner: ByteCounter, index: DocumentsBatchIndex,