mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-07-27 00:31:02 +00:00
Improve the Mtbl heed codec to only encode MTBL databases
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
use std::borrow::Cow;
|
||||
use std::marker::PhantomData;
|
||||
use oxidized_mtbl::Reader;
|
||||
|
||||
pub struct MtblCodec;
|
||||
pub struct MtblCodec<A>(PhantomData<A>);
|
||||
|
||||
impl<'a> heed::BytesDecode<'a> for MtblCodec {
|
||||
impl<'a> heed::BytesDecode<'a> for MtblCodec<&'a [u8]> {
|
||||
type DItem = Reader<&'a [u8]>;
|
||||
|
||||
fn bytes_decode(bytes: &'a [u8]) -> Option<Self::DItem> {
|
||||
@ -11,10 +12,10 @@ impl<'a> heed::BytesDecode<'a> for MtblCodec {
|
||||
}
|
||||
}
|
||||
|
||||
impl heed::BytesEncode<'_> for MtblCodec {
|
||||
type EItem = [u8];
|
||||
impl<'a, A: AsRef<[u8]> + 'a> heed::BytesEncode<'a> for MtblCodec<A> {
|
||||
type EItem = Reader<A>;
|
||||
|
||||
fn bytes_encode(item: &Self::EItem) -> Option<Cow<[u8]>> {
|
||||
Some(Cow::Borrowed(item))
|
||||
Some(Cow::Borrowed(item.as_bytes()))
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user