mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-07-27 16:51:01 +00:00
documents! macro accepts a single object again
This commit is contained in:
committed by
Clément Renault
parent
32d0e50a75
commit
1aef0e4037
@ -151,8 +151,17 @@ macro_rules! documents {
|
||||
($data:tt) => {{
|
||||
let documents = serde_json::json!($data);
|
||||
let mut file = tempfile::tempfile().unwrap();
|
||||
for document in documents.as_array().unwrap() {
|
||||
serde_json::to_writer(&mut file, &document).unwrap();
|
||||
|
||||
match documents {
|
||||
serde_json::Value::Array(vec) => {
|
||||
for document in vec {
|
||||
serde_json::to_writer(&mut file, &document).unwrap();
|
||||
}
|
||||
}
|
||||
serde_json::Value::Object(document) => {
|
||||
serde_json::to_writer(&mut file, &document).unwrap();
|
||||
}
|
||||
_ => unimplemented!("The `documents!` macro only support Objects and Array"),
|
||||
}
|
||||
file.sync_all().unwrap();
|
||||
unsafe { memmap2::Mmap::map(&file).unwrap() }
|
||||
|
Reference in New Issue
Block a user