Introduce a new meilitool to help the cloud team

This commit is contained in:
Clément Renault 2023-10-25 10:49:50 +02:00
parent 2614e7d9ca
commit 13416ccbf7
No known key found for this signature in database
GPG key ID: F250A4C4E3AE5F5F
6 changed files with 426 additions and 50 deletions

View file

@ -0,0 +1,24 @@
use std::borrow::Cow;
use std::convert::TryInto;
use meilisearch_types::heed::{BytesDecode, BytesEncode};
use uuid::Uuid;
/// A heed codec for value of struct Uuid.
pub struct UuidCodec;
impl<'a> BytesDecode<'a> for UuidCodec {
type DItem = Uuid;
fn bytes_decode(bytes: &'a [u8]) -> Option<Self::DItem> {
bytes.try_into().ok().map(Uuid::from_bytes)
}
}
impl BytesEncode<'_> for UuidCodec {
type EItem = Uuid;
fn bytes_encode(item: &Self::EItem) -> Option<Cow<[u8]>> {
Some(Cow::Borrowed(item.as_bytes()))
}
}