MeiliSearch/milli/src/heed_codec/obkv_codec.rs

23 lines
544 B
Rust
Raw Normal View History

2020-10-21 15:51:48 +02:00
use std::borrow::Cow;
2021-06-16 18:33:33 +02:00
use heed::BoxedError;
use obkv::{KvReaderU16, KvWriterU16};
2020-10-21 15:51:48 +02:00
pub struct ObkvCodec;
impl<'a> heed::BytesDecode<'a> for ObkvCodec {
type DItem = KvReaderU16<'a>;
2020-10-21 15:51:48 +02:00
fn bytes_decode(bytes: &'a [u8]) -> Result<Self::DItem, BoxedError> {
Ok(KvReaderU16::new(bytes))
2020-10-21 15:51:48 +02:00
}
}
impl heed::BytesEncode<'_> for ObkvCodec {
type EItem = KvWriterU16<Vec<u8>>;
2020-10-21 15:51:48 +02:00
fn bytes_encode(item: &Self::EItem) -> Result<Cow<[u8]>, BoxedError> {
item.clone().into_inner().map(Cow::Owned).map_err(Into::into)
2020-10-21 15:51:48 +02:00
}
}