diff --git a/meilidb-core/src/store/updates.rs b/meilidb-core/src/store/updates.rs index 14c839adb..7ec3b48aa 100644 --- a/meilidb-core/src/store/updates.rs +++ b/meilidb-core/src/store/updates.rs @@ -1,11 +1,31 @@ -use zlmdb::types::{OwnedType, Serde}; -use zlmdb::Result as ZResult; +use std::borrow::Cow; +use zlmdb::types::OwnedType; +use zlmdb::{Result as ZResult, BytesEncode, BytesDecode}; +use serde::{Serialize, Deserialize}; use crate::update::Update; use super::BEU64; +pub struct SerdeJson(std::marker::PhantomData); + +impl BytesEncode for SerdeJson where T: Serialize { + type EItem = T; + + fn bytes_encode(item: &Self::EItem) -> Option> { + serde_json::to_vec(item).map(Cow::Owned).ok() + } +} + +impl<'a, T: 'a> BytesDecode<'a> for SerdeJson where T: Deserialize<'a> + Clone { + type DItem = T; + + fn bytes_decode(bytes: &'a [u8]) -> Option { + serde_json::from_slice(bytes).ok() + } +} + #[derive(Copy, Clone)] pub struct Updates { - pub(crate) updates: zlmdb::Database, Serde>, + pub(crate) updates: zlmdb::Database, SerdeJson>, } impl Updates {