mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-07-27 00:31:02 +00:00
Simplify the the facet types
This commit is contained in:
@ -1,28 +0,0 @@
|
||||
use std::borrow::Cow;
|
||||
use std::convert::TryInto;
|
||||
use std::str;
|
||||
|
||||
use crate::heed_codec::StrBytesCodec;
|
||||
use crate::facet::value_encoding::{u64_from_bytes, u64_into_bytes};
|
||||
|
||||
pub struct FacetValueU64Codec;
|
||||
|
||||
impl<'a> heed::BytesDecode<'a> for FacetValueU64Codec {
|
||||
type DItem = (&'a str, u64);
|
||||
|
||||
fn bytes_decode(bytes: &'a [u8]) -> Option<Self::DItem> {
|
||||
let (name, bytes) = StrBytesCodec::bytes_decode(bytes)?;
|
||||
let value = bytes.try_into().map(u64_from_bytes).ok()?;
|
||||
Some((name, value))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> heed::BytesEncode<'a> for FacetValueU64Codec {
|
||||
type EItem = (&'a str, u64);
|
||||
|
||||
fn bytes_encode((name, value): &Self::EItem) -> Option<Cow<[u8]>> {
|
||||
let value = u64_into_bytes(*value);
|
||||
let tuple = (*name, &value[..]);
|
||||
StrBytesCodec::bytes_encode(&tuple).map(Cow::into_owned).map(Cow::Owned)
|
||||
}
|
||||
}
|
@ -1,9 +1,7 @@
|
||||
mod facet_value_f64_codec;
|
||||
mod facet_value_i64_codec;
|
||||
mod facet_value_string_codec;
|
||||
mod facet_value_u64_codec;
|
||||
|
||||
pub use self::facet_value_f64_codec::FacetValueF64Codec;
|
||||
pub use self::facet_value_i64_codec::FacetValueI64Codec;
|
||||
pub use self::facet_value_string_codec::FacetValueStringCodec;
|
||||
pub use self::facet_value_u64_codec::FacetValueU64Codec;
|
||||
|
Reference in New Issue
Block a user