2022-10-31 07:55:19 +01:00
|
|
|
use std::borrow::Cow;
|
|
|
|
|
2023-11-22 18:21:19 +01:00
|
|
|
use meilisearch_types::heed::{BoxedError, BytesDecode, BytesEncode};
|
2022-10-31 07:55:19 +01:00
|
|
|
use uuid::Uuid;
|
|
|
|
|
|
|
|
/// A heed codec for value of struct Uuid.
|
|
|
|
pub struct UuidCodec;
|
|
|
|
|
|
|
|
impl<'a> BytesDecode<'a> for UuidCodec {
|
|
|
|
type DItem = Uuid;
|
|
|
|
|
2023-11-22 18:21:19 +01:00
|
|
|
fn bytes_decode(bytes: &'a [u8]) -> Result<Self::DItem, BoxedError> {
|
|
|
|
bytes.try_into().map(Uuid::from_bytes).map_err(Into::into)
|
2022-10-31 07:55:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl BytesEncode<'_> for UuidCodec {
|
|
|
|
type EItem = Uuid;
|
|
|
|
|
2023-11-22 18:21:19 +01:00
|
|
|
fn bytes_encode(item: &Self::EItem) -> Result<Cow<[u8]>, BoxedError> {
|
|
|
|
Ok(Cow::Borrowed(item.as_bytes()))
|
2022-10-31 07:55:19 +01:00
|
|
|
}
|
|
|
|
}
|